... | @@ -4,23 +4,27 @@ When creating a field that provides several list of known options (i.e. status, |
... | @@ -4,23 +4,27 @@ When creating a field that provides several list of known options (i.e. status, |
|
|
|
|
|
1. **_Static "Select list"_**
|
|
1. **_Static "Select list"_**
|
|
|
|
|
|
|
|
\
|
|
**Pros**: Native. No development except the list creation while defining the entity form.\
|
|
**Pros**: Native. No development except the list creation while defining the entity form.\
|
|
Simple access (views, etc), option data available directly at the entity storage.\
|
|
Simple access (views, etc), option data available directly at the entity storage.\
|
|
|
|
\
|
|
**Cons**: Not reusable: Hard coded on entity definition at every form (or webform) it has. \
|
|
**Cons**: Not reusable: Hard coded on entity definition at every form (or webform) it has. \
|
|
Static: Requires a drupal developer/admin to change the options list at field form properties.
|
|
Static: Requires a drupal developer/admin to change the options list at field form properties.
|
|
2. **_Using a custom entity reference_**\
|
|
2. **_Using a custom entity reference_**\
|
|
|
|
\
|
|
**Pros:** Native & dynamic, list of values can be updated at any time by any privileged user, without having to be a developer.\
|
|
**Pros:** Native & dynamic, list of values can be updated at any time by any privileged user, without having to be a developer.\
|
|
Reusable on other fields & entities.\
|
|
Reusable on other fields & entities.\
|
|
Highly extensible.
|
|
Highly extensible. \
|
|
|
|
\
|
|
**Cons:** Requires object storage / data model extension by creating a new entity type for every select list. \
|
|
**Cons:** Requires object storage / data model extension by creating a new entity type for every select list. \
|
|
Object storage has the pointer to the relation, but not the data itself. Views and data access a bit more complex (require define relations).
|
|
Object storage has the pointer to the relation, but not the data itself. Views and data access a bit more complex (require define relations).
|
|
3. **Dynamic select list.**\
|
|
3. **Dynamic select list.**\
|
|
**Pros**: Dynamic, list of values can be updated at any time by any privileged user, without having to be a developer.
|
|
\
|
|
Reusable on other fields & entities.\
|
|
**Pros**: Dynamic, list of values can be updated at any time by any privileged user, without having to be a developer. Reusable on other fields & entities.\
|
|
Object storage contains the data without having to add relations.\
|
|
Object storage contains the data without having to add relations.\
|
|
|
|
\
|
|
**Cons**: Requires some (minimal) custom development (not drupal native).
|
|
**Cons**: Requires some (minimal) custom development (not drupal native).
|
|
|
|
|
|
|
|
|
|
## Implementing a Dynamic Select List (type 3)
|
|
## Implementing a Dynamic Select List (type 3)
|
|
|
|
|
|
The Dynamic Select list relies on "guifi_options" Entity type, so the first action is add the list of options into that table, with every key & title pair, and groped by a type.
|
|
The Dynamic Select list relies on "guifi_options" Entity type, so the first action is add the list of options into that table, with every key & title pair, and groped by a type.
|
... | @@ -38,10 +42,10 @@ Once introduced the list of options you want, and to add the dynamic select list |
... | @@ -38,10 +42,10 @@ Once introduced the list of options you want, and to add the dynamic select list |
|
` `$query = $database->query(`"SELECT field_key_value, title`\
|
|
` `$query = $database->query(`"SELECT field_key_value, title`\
|
|
<span dir="">FROM {guifi__field_type} t, {guifi__field_weight} w, {guifi_field_data} l, {guifi__field_key} k </span>\
|
|
<span dir="">FROM {guifi__field_type} t, {guifi__field_weight} w, {guifi_field_data} l, {guifi__field_key} k </span>\
|
|
`WHERE t.field_type_value = 'im_groups' `\
|
|
`WHERE t.field_type_value = 'im_groups' `\
|
|
` AND t.entity_id = w.entity_id AND w.entity_id=l.id `\
|
|
`AND t.entity_id = w.entity_id AND w.entity_id=l.id`\
|
|
` AND w.entity_id=k.entity_id AND w.bundle='guifi_options' `\
|
|
`AND w.entity_id=k.entity_id AND w.bundle='guifi_options'`\
|
|
` AND l.bundle='guifi_options' AND k.bundle='guifi_options' `\
|
|
`AND l.bundle='guifi_options' AND k.bundle='guifi_options'`\
|
|
` AND w.entity_id=l.id AND w.entity_id=k.entity_id `\
|
|
`AND w.entity_id=l.id AND w.entity_id=k.entity_id`\
|
|
`ORDER BY w.field_weight_value, title");`\
|
|
`ORDER BY w.field_weight_value, title");`\
|
|
`$result = $query->fetchAllKeyed(0,1);`\
|
|
`$result = $query->fetchAllKeyed(0,1);`\
|
|
`return $result;`\
|
|
`return $result;`\
|
... | @@ -53,9 +57,6 @@ Once introduced the list of options you want, and to add the dynamic select list |
... | @@ -53,9 +57,6 @@ Once introduced the list of options you want, and to add the dynamic select list |
|
1. Add element field,use "[remote select](https://www.drupal.org/project/webform_remote_select)" field type. Once you edit the properties, specify:
|
|
1. Add element field,use "[remote select](https://www.drupal.org/project/webform_remote_select)" field type. Once you edit the properties, specify:
|
|
1. The endpoint provided by the mentioned above view. Example:\
|
|
1. The endpoint provided by the mentioned above view. Example:\
|
|
<http://127.0.0.1/api/v1/select_options?option_type=execution_status&_format=json>
|
|
<http://127.0.0.1/api/v1/select_options?option_type=execution_status&_format=json>
|
|
2. "Headers":
|
|
2. "Headers": `{'Content-Type': 'application/json'}`
|
|
`{'Content-Type': 'application/json'}`
|
|
3. "Response items key": `key`
|
|
3. "Response items key":
|
|
4. "Response items value": `title` |
|
`key`
|
|
\ No newline at end of file |
|
4. "Response items value":
|
|
|
|
`title` |
|
|