I created content-type that contains two fields:
- an ordinary
List (text)
-field with the widget set toSelect-list
. - a
Text
-field with the widget set toSelect-or-other
Both fields have allowed values listed as key-value-pairs.
Next I created two identical rules that fire before saving a node of that content type:
- Rule for List (text)-field
- Create a new custom entity
- Save the selected field-content from field 1 to the a text-field in new entity.
- Rule for select-or-other-field
- Create a new custom entity
- Save the selected field-content from field 2 to a text-field in the new entity.
While Rule 1 stores the value as expected, rule 2 stores the key. (They also check if the respected field has changed and reset it after storing.)
I tried using different tokens to explicitly select storing the value but none of them worked.
I think to be consistent with core-fields the default way should be to provide the value and optionally to provide the key via a token like [node:field-testliste-or-other:key].
Here the list of non-core modules installed:
Administration menu (admin_menu) 7.x-3.0-rc5
Chaos tools (ctools) 7.x-1.9
Devel (devel) 7.x-1.5
Devel generate (devel_generate) 7.x-1.5
Entity Construction Kit (eck) 7.x-2.0-rc8
Entity Reference (entityreference) 7.x-1.1
Select (or other) (select_or_other) 7.x-2.22
Entity API (entity) 7.x-1.7
Entity tokens (entity_token) 7.x-1.7
Token (token) 7.x-1.6
Rules (rules) 7.x-2.9
Rules UI (rules_admin) 7.x-2.9
Views (views) 7.x-3.14
Views UI (views_ui) 7.x-3.14
Here are the two rules:
Rule 1:
{ "rules_copy_value_list_field_entity_reference" : {
"LABEL" : "Copy VALUE List field -\u003E Entity Reference",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "php" ],
"ON" : { "node_presave--test_basic" : { "bundle" : "test_basic" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_textliste" } },
{ "NOT data_is" : {
"data" : [ "node-unchanged:field-textliste" ],
"value" : [ "node:field-textliste" ]
}
}
],
"DO" : [
{ "entity_create" : {
"USING" : { "type" : "auftragshistorie", "param_type" : "auftragshistorie" },
"PROVIDE" : { "entity_created" : { "historie" : "Historie" } }
}
},
{ "data_set" : {
"data" : [ "historie:field-beschreibung" ],
"value" : "[node:field-textliste]"
}
},
{ "entity_save" : { "data" : [ "historie" ], "immediate" : "1" } },
{ "list_add" : { "list" : [ "node:field-historie" ], "item" : [ "historie" ] } },
{ "data_set" : {
"data" : [ "node:field-textliste" ],
"value" : { "select" : "", "php" : { "code" : "return \u0022\u0022;" } }
}
}
]
}
}
Rule 2:
{ "rules_copy_value_list_field_or_other_entity_ref" : {
"LABEL" : "Copy VALUE List field or other -\u003E Entity Reference",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "php" ],
"ON" : { "node_presave--test_basic" : { "bundle" : "test_basic" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_testliste_or_other" } },
{ "NOT data_is" : {
"data" : [ "node-unchanged:field-testliste-or-other" ],
"value" : [ "node:field-testliste-or-other" ]
}
}
],
"DO" : [
{ "entity_create" : {
"USING" : { "type" : "auftragshistorie", "param_type" : "auftragshistorie" },
"PROVIDE" : { "entity_created" : { "historie" : "Historie" } }
}
},
{ "data_set" : {
"data" : [ "historie:field-beschreibung" ],
"value" : "[node:field-testliste-or-other]"
}
},
{ "entity_save" : { "data" : [ "historie" ], "immediate" : "1" } },
{ "list_add" : { "list" : [ "node:field-historie" ], "item" : [ "historie" ] } },
{ "data_set" : {
"data" : [ "node:field-textliste" ],
"value" : { "select" : "", "php" : { "code" : "return \u0022\u0022;" } }
}
}
]
}
}
Comments
Comment #2
guidot CreditAttribution: guidot commentedI also tried setting different formatters on
costum display settings
for token. Didn't help.Comment #3
seanenroute CreditAttribution: seanenroute commentedI've just tested with Rules and was not able to get the label of the field to use to replace the nodes title. Tried a number of different token :label, :raw, name etc. with no success. Is there a work around for this?
Comment #4
daften CreditAttribution: daften at Dropsolid commentedClosing as outdated because no activity in a long time and Drupal 7 goes EOL soon. Feel free to re-open if needed.
Comment #5
daften CreditAttribution: daften at Dropsolid commentedComment #6
mixael CreditAttribution: mixael commentedSame problem with rules to sent emails - keys are sent - not values.
In views all is ok. Display settings - "Select other".