3

I have pre-existing node authored by each user. However, for presentation purposes, I use a Webform to collect data from the user.

Existing Node: Assessment

  • field_question1
  • field_question2
  • field_question3

Webform

  • field_question1
  • field_question2
  • field_question3

On submit, I would like to compare "the user submitting the Webform" with the author of existing nodes, then set the field values of the submitter's existing node with the new values from the submitted webform.

This worked well in Drupal 7, but in Drupal 8 I don't seem to understand the syntax, nor do I see a place to set up or pass variables.

Can this be done in the current state of Drupal 8 Rules?

1
  • It looked to me like the module was ready and usable if you could do it with code, but the UI was in need of polish and documentation. However, after 3 days and no one seeming to hint that they knew of a way to do this, I am just going to mark it answered. Thank you for your time kiamlaluno and pierre.
    – Jamie
    Apr 19, 2017 at 16:57

3 Answers 3

1

Can this be done in the current state of Drupal 8 Rules?

To my knowledge the answer to your question is No (it's part of what this is all about).

If you're in for getting a better understanding about all this, then have a look at these links:

One never realizes what has been done, only what remains to be done ...

1

Here's a simple Rule that will react on a webform submission and create a new node of type "Article" with the article title set to the submission time to show how webform submission values may be used to set node values. This Rule assumes you have the default webform type "Contact" enabled.

Use the Rules 8.x-3.x-dev version and you can import this Rule and try it out for yourself.

langcode: en
status: true
dependencies: {  }
id: create_a_new_node_after_webform_submission
label: 'Create a new node after webform submission'
events:
  -
    event_name: 'rules_entity_insert:webform_submission--contact'
description: ''
tags: {  }
weight: 0
config_version: '3'
expression:
  id: rules_rule
  uuid: 55a23cf1-afbb-4801-87be-842423a008cf
  weight: 0
  conditions:
    id: rules_and
    uuid: 51465df7-ce1e-4e50-9ed6-34f7dba04355
    weight: 0
    conditions: {  }
  actions:
    id: rules_action_set
    uuid: e9b1732f-9d09-4b1f-965e-78a18288ed12
    weight: 0
    actions:
      -
        id: rules_action
        uuid: e0be8c6a-1ddc-45c9-8dc0-ae40d8f7451d
        weight: 0
        context_values:
          type: article
          title: '{{ webform_submission.created.value | format_date(''medium'') }}'
        context_mapping: {  }
        context_processors:
          type:
            rules_tokens: {  }
          title:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: 'rules_entity_create:node'
      -
        id: rules_action
        uuid: 4399f655-c6e7-4969-97a2-e8a7f8da8c7e
        weight: 0
        context_values:
          message: 'Article created: {{ webform_submission.created.value | format_date(''medium'') }}'
          type: warning
          repeat: false
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message
2
  • I see my answer is really a response to the answer from @Andrew Wasson, rather than a response to the original post. But it does serve to demonstrate how Rules can be used with Webform. I'll update my answer with information about using an existing node, like the original poster asked.
    – anonymous
    Jan 30, 2020 at 10:21
  • Sorry for taking the subject off topic but your resulting post is interesting all the same. I've struggled with Rules for Drupal 8 and have found it much less hassle to build custom handlers like the one I described in my post. That could be because I adopted Drupal 8 when it first landed nearly 5 years ago and Rules is still in a state of development. Your YML is obviously worth looking into. Thanks for that. Feb 6, 2020 at 23:47
0

As far as I know, Rules can't create a node on a webform submission.

A better approach is to create a custom web form handler to produce the node for you. I submitted the recipe to do so in the following posting: How to create a node out of a webform submission?

3
  • Of course Rules can create a node on webform submission. Complete example below.
    – anonymous
    Jan 30, 2020 at 10:08
  • Actually, this isn't even what the original poster was asking - the question was about an existing node and setting values in that existing node from a webform submission.
    – anonymous
    Jan 30, 2020 at 10:17
  • Thanks @anonymous. You're right. I didn't see that they were appending to existing nodes. My answer doesn't help in that regard. Feb 6, 2020 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.