Hi,

any webform element added to a webform is not being recognized by the business rules !

Please reproduce the issue by following the below steps:

1) Install the webform module.

2) The webform module come shipped with a built-in "contact webform"

3) Goto: /admin/structure/webform/manage/contact and you will find that this webform has 4 elements added to it:
_ Your Name (name)
_ Your Email (email)
_ Subject (subject)
_ Message (message)

4) Now, lets say i want edit a submission of the "contact" webform and update the "your Name" field value using business rules, so i will have to create:

EVENT:
After updating Entity

ACTION:
Set field Value

5) Try to create a "set field value" action with the below configuration:

Target Entity Type: Webform Submission
Target Bundle: Contact

and here is the problem inside the "Field" section!!!!!

You will not find the elements added to the contact webform inside the field section which are:
_ Your Name (name)
_ Your Email (email)
_ Subject (subject)
_ Message (message)

see below image:

Set fields value - fields section

As you can see in the image above, there is no listing for the elements available in the webform contact such as:
_ Your Name (name)
_ Your Email (email)
_ Subject (subject)
_ Message (message)

any help on this subject ?

Having the webform elements appear in the "field" section will give the BR module a huge thumb up in term of flexibility.

Thank you,

Comments

C.E.A created an issue. See original summary.

c.e.a’s picture

Issue summary: View changes
wombatbuddy’s picture

Hi,
as is known 'Webform' module enables to create 'Computed Elements'. In that regard, could you provide an example of real use case which might need altering of webform elements from a rule.

c.e.a’s picture

StatusFileSize
new35.82 KB

Hi @wombatbuddy,

I aware of the "computed element" offered by the "webform" module but it does not resolve this issue at all.

Giving a real use case example will take a lots of explanations but I will try my best to approach the idea to you !

First of all I will take the "Contact" webform as an example for the sake of simplicity because it comes already built with 4 elements:
_ Your Name (name)
_ Your Email (email)
_ Subject (subject)
_ Message (message)

Now, say you want upon you insert a new submission of the webform "contact", to copy the value of Your name (name) webform element to the Username of the profile of the current logged in user... if you are familiar with the business rules module, this will be a very easy task and can be done by following the below steps:

REACTS ON EVENT:
Entity insert
Target Entity Type: Webform Submission
Target Bundle: Contact

VARIABLE:
Type: Empty Entity variable
Name: Current User - Empty Entity variable
Target Entity Type: User
Target Bundle: User

ACTION 1
Type: Fetch entity variable by id
Target Entity Type: User
Target Bundle: User
Entity id field: User ID [uid]
Empty variable: Current User - Empty Entity variable
Value: {{current_user->uid}}

ACTION 2
Type: Set values to entity variable
Target Entity Type: User
Target Bundle: User
Entity variable: Current User - Empty Entity variable
Fields:
_ string: Name [name] = [webform_submission:values:name]

ACTION 3
Type: Save entity variable
Target Entity Type: User
Target Bundle: User
Entity variable: Current User - Empty Entity variable

Now proceed to the contact webform and submit it, you will notice the Your Name value has been copied to the username field of the current logged in user profile.

WHAT IF ?!
What if , for any reason, you want to do just the opposite of the above example ?!

In another words, what if you want upon insert a new submission of the webform "contact", to replace the value of Your name (name) webform element by the value of the Username of the profile of the current logged in user...

This (what if) use case, is not currently possible because the Business rules module allow you to set values to only built-in existed fields of a webform such as:
_ integer: Submission ID [sid]
_ string_long: Notes [notes]
_ integer: Serial Number [serial]
_ ...

and not the added elements which are in this case:
_ Your Name (name)
_ Your Email (email)
_ Subject (subject)
_ Message (message)

In other words, if you create a new business rules action of:
Type: Set values to entity variable
Target Entity Type: Webform submission
Target Bundle: Contact

The only fields available to set values are:
Available fields

and as you can see in the above image, none of the below elements are available inside the Set values to entity variable action:
Your Name (name)
_ Your Email (email)
_ Subject (subject)
_ Message (message)

Proposed Solution:

Make any added webform element available inside the Set values to entity variable action like the below image:

Proposed Solutions

I hope the issue is better clarified now...

Thank you for your interest,

wombatbuddy’s picture

That is you are talking about a hypothetical situation. I get it.

c.e.a’s picture

What I am talking about is very common to face any Web project and I am facing it now in my current project...

Plenty of times where I found myself in need to what is explained above but unfortunately it is not implemented yet...

Using Drupal and Business rules, you may copy field's values between two different entities in both directions, however only with the webform submission entity is possible to copy from itand not copy to it.

Diagram for copying field's values between entities is explained as below: (from >>> to)

Node >>> User
User >>> Node

Node >>> Taxonomy
Taxonomy >>> Node

Node >>> Group
Group >>> Node

User >>> Node
Node >>> User

User >>> Taxonomy
Taxonomy >>> User

User >>> Group
Group >>> User

Group >>> Taxonomy
Taxonomy >>> Node

Webform submission >>> Node
Webform submission >>> User
Webform submission >>> Group
Webform submission >>> Taxonomy

All the above scenarios are possible but the below are currently not possible:

Node >>> Webform submission
Group >>> Webform submission
User >>> Webform submission
Taxonomy >>> Webform submission
Webform submission >>> Webform submission

wombatbuddy’s picture

I understand what you want (in technical terms), moreover I already have realized this feature for 'Rules' module. I just wanted to hear a real business use case where this feature is needed :)

You say:

In another words, what if you want upon insert a new submission of the webform "contact", to replace the value of Your name (name) webform element by the value of the Username of the profile of the current logged in user...

But for this you even need not to create any rules. Because you can insert '[current-user:account-name]' token as default value of 'Your name' webform element.

jptillman’s picture

** comment removed **

sebaz’s picture

@wombatbuddy

I'm going to give you better example of usecase.

Webform with Entity reference element. You are going to use views filtered options by BR and you don't have access to parent field configuration because there is an error:

PHP message: Error: Call to a member function getTargetEntityTypeId() on null in /business_rules/src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php on line 285

    /** @var \Drupal\field\Entity\FieldConfig $field_config */
      $field_config = $this->util->request->get('field_config'); // here is null 
      $entity_type = $field_config->getTargetEntityTypeId(); 

$field_config is null beacuse of webform element not recognised as a field and can't find 'field_config' for it.

sebaz’s picture

c.e.a’s picture

+1 to @SebaZ example in #9

wombatbuddy’s picture

@SebaZ, in #3 I asked to provide an example of use case which might need altering of webform elements from a rule.

But regards to your use case, would you describe it in simple words? Whad do you need to do?
Maybe we can find an alternative solution.

sebaz’s picture

I mean "Make field dependant using views" option not working with webforms. In #9 I have explained what I need.

Drop down list dependant from another list, reloaded by AJAX when I change parent field value.

wombatbuddy’s picture

@SebaZ,
Ok, what data does contain the list 1?
What data contains dependent list 2?
What are the conditions for displaying data in the list 2?

sebaz’s picture

Does it matter what data?

1. Entity Reference to taxonomy terms.
2. Entity Reference to taxonomy terms filtered by 1. value.

wombatbuddy’s picture

@SebaZ,
If I don't understand the task, then I'm not motivated to help with this.

wombatbuddy’s picture

@SebaZ,
As a workaround, you can use 'eForm' module instead of 'Webform' module.
It will enable you to create a webform with a dependent field like in the "Dependent field" tutorial.

sebaz’s picture

Thank you for your suggestion. I would make new content type rather than using eform. Webforms are great, Business Rules are great too. Would like to see it working together in all features. Especially in ""Make field dependant using views"" :)

My posts were not looking for help, just wanted to help fix that issue giving examples and some usecase.

wombatbuddy’s picture

@SebaZ,
Also exists a good module named 'Webform Simple Hierarchical Select'.
It enables to use 'Webform' module and create dependent fields in a convenient way.

sebaz’s picture

StatusFileSize
new19.08 KB

@wombatbuddy
Webform_SHS only visualizes hierarchical vocabulary not allowing dependant fields. Webform_SHS no dependant options

When you need to filter terms by many conditions it is not possible to make hierarchical vocabulary and SHS will not help.

sebaz’s picture

sebaz’s picture

wombatbuddy’s picture

@SebaZ,
Would you describe the task in simple words, without technical terms (in a marketing team manner).
What does hypothetical client want?
For instance:
"A user need to select states and cities and submit this info..."
(I want to insure that a ready solution is not exists).

sebaz’s picture

School, courses. And courses are filtered by few conditions like:
- level of study (bachelor/master),
- type of study (full-time/part-time)
- language of study.

Each parameter is another vocabulary with reference to it in every course.
Biology bachelor, part-time, english
Biology bachelor, full-time, swedish
etc.

When I select language, type and level of study I need to show only fitting courses.
Is it enough explanation?

wombatbuddy’s picture

Yes that's enough for now.
I only want to clarify, are course represented by node or by taxonomy term?

sebaz’s picture

The first idea was to make courses as taxonomy but it can be made by nodes too. It changes nothing to lack of dependant select fields.

wombatbuddy’s picture

Ok, I will think on it.

c.e.a’s picture

Category: Bug report » Feature request
Priority: Major » Normal
wombatbuddy’s picture

@SebaZ,
I tried to solve your task (about school, courses) for a node creation form, using 'Business Rules' dependent fields.
But it seems to me that this is impossible.
It looks like 'Business Rules' approach works only for two dependent fields and not for more.
Is it so?

sebaz’s picture

@wombatbuddy
It is not the problem because I can make computed field with value needed to dynamic view for entity reference. It works on core nodes system but not on Webforms.

When you analyze our last discussion you will realize that problem is with Webforms and Business Rules which not recognizes Webform fields as normal fields and you can not use BR dependant fields feature on Webforms. Details #9

PS. I wanted to use Webforms to gather admission informations because there will be many admissions during academic year and cloning Webform with little changes would be bether solution than core nodes. With core nodes I will have to make new content type for every admission which will change gathered data.

wombatbuddy’s picture

@SebaZ
Do you mean that you use 'Computed Field' module additionally?

sebaz’s picture

Nope. This module works only after submit form. I just used JS to fill hidden field value: arg1,arg2,arg3,arg4 and then used it with Business Rules dependant feature. Filtered View as Entity Reference takes arguments like I gave in field. That's it :)

This is impossible in Webforms. Business Rules dependant feature is not working, gives error when it tries to load textfield to configure it. Details in #9

wombatbuddy’s picture

@SebaZ
It looks like that for your task it's more easy to create a custom solution for Webform, which will be independent from 'Business Rules'.

irsar’s picture

sebaz Did you get this working? We have a similar requirement where we need to populate the second dropdown values based on the selected value in the first dropdown. Entity reference view and business rule works fine in a node, but when we try to do the same in the webform its not working and not able to filter the entity select values.

sebaz’s picture

No, I've dropped the idea of using Webforms to this task. Entityform did what I want without special integration.

irsar’s picture

Oh! EntityForm is not available for Drupal 9, wonder if there is anything else that can be used to achieve this feature.