To achieve your goal (= "... make entity fields appear in Rules when converting a Webform submission to node ...", as in your question title), you can use a technique similar to what is described in my answer to "How to do a data comparison to submitted webform data when using the Rules module?". For short:
- Add an extra Rules Action to
Add a variable
(for each of the Webform components to transpose the information across, with a value assigned to it equal to your [data:ComponentName-value-raw]
(and with a data type which equals the data type of your Webform component).
- In your subsequent Rules Actions you can refer to the value of these variables you just added (that's the clue!).
Demo
Webform components
Assume a webform with form_id=191
and with these Webform Components:
- Label = Title, Machine name =
demoform_title
, Data type = Textfield.
- Label = Text, Machine name =
demoform_text
, Data type = Textarea.
- Label = Number, Machine name =
demoform_number
, Data type = Number.
- Label = Option, Machine name =
demoform_option
, Data type = Select options (single value).
Article content type
Assume an Article content type with these fields:
- Label = Title, Machine name =
title
, Field type = Node module element.
- Label = Body, Machine name =
body
, Field type = Long text and summary.
- Label = Free Format Nr, Machine name =
field_free_format_nr
, Field type = Integer.
- Label = OptionList, Machine name =
field_optionlist
, Field type = List(text).
Custom Rule
Here is a custom rule (in Rules export format), which will create a new node (of type Article
), and which will use the data included in the above mentioned Webform components:
{ "rules_create_a_node_from_webform_data" : {
"LABEL" : "Create a node from webform data",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "webform_rules", "rules" ],
"ON" : { "webform_rules_submit" : [] },
"IF" : [
{ "webform_has_id" : {
"form_id" : [ "form_id" ],
"selected_webform" : { "value" : { "webform-client-form-191" : "webform-client-form-191" } }
}
}
],
"DO" : [
{ "drupal_message" : { "message" : "The webform submitted contains these fields:\r\n\u003C\/ul\u003E\r\n\u003Cli\u003Ethe field labeled \u0022[data:demoform_title-title]\u0022 which has value \u0022[data:demoform_title-value-raw]\u0022.\u003C\/li\u003E\r\n\u003Cli\u003E the field labeled \u0022[data:demoform_text-title]\u0022 which has value \u0022[data:demoform_text-value-raw]\u0022.\u003C\/li\u003E\r\n\u003Cli\u003E the field labeled \u0022[data:demoform_number-title]\u0022 which has value \u0022[data:demoform_number-value-raw]\u0022.\u003C\/li\u003E\r\n\u003Cli\u003E the field labeled \u0022[data:demoform_option-title]\u0022 which has value \u0022[data:demoform_option-value-raw]\u0022.\u003C\/li\u003E\r\n\u003C\/ul\u003E" } },
{ "variable_add" : {
"USING" : { "type" : "text", "value" : "[data:demoform_text-value-raw]" },
"PROVIDE" : { "variable_added" : { "var_demoform_text" : "Form variable text" } }
}
},
{ "variable_add" : {
"USING" : { "type" : "text", "value" : "[data:demoform_number-value-raw]" },
"PROVIDE" : { "variable_added" : { "var_demoform_number_text" : "Form variable number text" } }
}
},
{ "data_convert" : {
"USING" : { "type" : "integer", "value" : [ "var-demoform-number-text" ] },
"PROVIDE" : { "conversion_result" : { "var_demoformvar_number" : "Form variable number" } }
}
},
{ "variable_add" : {
"USING" : { "type" : "text", "value" : "[data:demoform_option-value-raw]" },
"PROVIDE" : { "variable_added" : { "var_demoform_option" : " Form variable option" } }
}
},
{ "entity_create" : {
"USING" : {
"type" : "node",
"param_type" : "article",
"param_title" : "[data:demoform_title-value-raw]",
"param_author" : [ "user" ]
},
"PROVIDE" : { "entity_created" : { "article_created" : "Created article" } }
}
},
{ "data_set" : {
"data" : [ "article-created:body:value" ],
"value" : [ "var-demoform-text" ]
}
},
{ "data_set" : {
"data" : [ "article-created:field-free-format-nr" ],
"value" : [ "var-demoformvar-number" ]
}
},
{ "data_set" : {
"data" : [ "article-created:field-optionlist" ],
"value" : [ "var-demoform-option" ]
}
},
{ "data_set" : { "data" : [ "article-created:comment" ], "value" : "0" } },
{ "entity_save" : { "data" : [ "article-created" ], "immediate" : "1" } },
{ "drupal_message" : { "message" : "A new article got created, with nid=[article-created:nid] and url=[article-created:url]" } }
]
}
}
Some more details about the Rules Actions that were added:
Show a message on the site
: This is just for debugging/demo purposes (remove it you don't want/need it anymore). Here is a sample message that gets displayed after submitting a webform:
The webform submitted contains these fields:
- the field labeled "Title" which has value "Some interesting title of
my webform".
- the field labeled "Text" which has value "Just some text,
with some additional text and yet another line and another one".
- the field labeled "Number" which has value "842316".
- the field labeled "Option" which has value "A".
Add a variable
(twice): To make the value of the Webform components demoform_number
and demoform_option
available in subsequent Rules Actions. Note that for demoform_number
an additional Rules Action Convert data type
is needed to get it to work.
Set a data value
(3 times): To populate the node's body and the 2 node fields, using the variables created in a preceeding Rules Action.
Set a data value
: To set "Comments closed" for the node being created (this is an optional Rules Action, just an illustration of other things you can do with such node being created).
Save entity
: To actually save the node.
Show a message on the site
: This is just for debugging/demo purposes (remove it you don't want/need it anymore). Here is a sample message that gets displayed after submitting a webform:
A new article got created, with nid=123
and url=http://www.example.com/node/123
Final result
After submitting the webform with data as in the sample above, a new article (with node id = 123
) got created, and with these details about that node:
- Title: Some interesting title of my webform
Body:
Just some text,
with some additional text
and yet another line
and another one
Free Format Nr: 842316
- OptionList: Advanced (the label corresponding to key-value "
A
")
Notes
The custom rule in this answer does not require the (dangerous) PHP filter to be enabled (as opposed to what is mentioned in the currently accepted answer). Nor does it require the patch mentioned in the currently accepted answer.
This answer should address your "Step 4" (in your question). While it seems to me that you don't need "Step 3" (in your question). Unless you want to create multiple types of nodes, e.g. based on some value specified in any of your webform components. If that's the case, all you need to do is to further improve the set of the Rules Actions in my sample rule, by also using the Conditional Rules module.