The "Entity has field" condition is working for me to detect whether an entity has a field, however it doesn't give me access to that field. The only that I've been able to do to get access to the field in later conditions/actions is to use the "Entity is of bundle" condition, which then gives access to all the fields of the bundle. This can be a major hassle, though, if there are a large number of bundles that you want to have the same rule applied to based on a field.
Unless I'm doing something wrong, I feel like "Entity has field" needs to actually give access to use the field regardless of checking for a bundle.
Comment | File | Size | Author |
---|---|---|---|
#17 | rules-condition-2.png | 9.97 KB | StuartL |
#17 | rules-condition.png | 9.94 KB | StuartL |
Comments
Comment #2
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedI spent a while going through API documentation and code, and it's not clear to me what the best way to provide access to individual fields without specifying a bundle is. The
EntityDataDefinition
class doesn't seem to have any mechanism for either adding individual fields to the properties list or manually specifying fields, so it seems this would either have to be a class extending EntityDataDefinition that could be used to override the properties that are returned, or a separate class altogether that might wrap EntityDataDefinition and also add field definitions that should be included based on any other Rules conditions.It would be great if you could simply use
assertMetadata
to inject the field, similarly to how theEntityIsOfBundle
class works, but again it just doesn't seem like EntityDataDefinition supports that use case.I'm happy to put some effort into a patch for solving this, but I'm not sure what the best direction to go is.
Comment #3
errev CreditAttribution: errev commented+
Comment #4
rferguson CreditAttribution: rferguson commented+ 1 for this, I can't find a way to get it to validate on field values using data comparison, even when having "entity has field"
Comment #5
superlolo95 CreditAttribution: superlolo95 commented+1
Comment #6
StuartL CreditAttribution: StuartL commented+1 - I was hoping to be able to use Token values while this issue is being worked on, but I haven't had any success.
Comment #7
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi, I have been working on #2664280: Select lists in action & condition configuration forms and this now gives a drop-down selection list for the fields to choose. Maybe this will help you as it seems to be working fine for me and does not require the 'Entity is of bundle' condition to be added.
Comment #8
StuartL CreditAttribution: StuartL commentedThanks for your contribution, Jonathan. Unfortunately this didn't work for me in Drupal 8.4.0 - I have yet to try it in Drupal 8.4.2.
Comment #9
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi StuartL
What exactly is not working for you? I will try to help if you can be more specific.
Jonathan
Comment #10
StuartL CreditAttribution: StuartL commentedHi Jonathan,
I'll try and get something more specific for you, but many of the pages are now blank when displayed (e.g. after choosing a condition). Also, I am not able to select fields using the selector when setting up a redirect action, even after checking that a field exist.
Thanks,
Stuart
Comment #11
StuartL CreditAttribution: StuartL commentedHi Jonathan,
A quick update: I updated to Drupal 8.4.2 and the behavior has not changed. Trying to add the condition 'Content type' leads to a blank page. After adding 'Entity has field', I am able to select a field from a dropdown (better than before), but when adding the action 'Page ridirect', the field does not appear when using the data selector method - I start typing 'node.' and there is nothing that resembles the field in the list.
Thanks,
Stuart
Comment #12
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedWhat event is the rule reacting to? For node-related events I do not see a condition named "Content Type". Did you mean "Entity is of type" or "Node is of type" or something else?
Comment #13
StuartL CreditAttribution: StuartL commentedHi Jonathan,
Please see the attached screenshot for the configuration.
The event is: 'After saving new content'. The conditions are checking that the content type is 'Video', and that the entity has a certain field. That field is an entity reference. The redirect should direct to the referenced node.
After applying your patch, and choosing 'After saving new content' as the event, 'Content type' is an available condition but directs to a blank page.
Thanks,
Stuart
Comment #14
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi Stuart,
This is a bit strange, because I do not get any condition which is labelled simply "content type", as mentioned before. Here's my condition selection (on 8.4, latest Rules dev, for event 'after saving new content').
Neither "Entity is of type" nor "Node is of type" produce the caption "Condition: Content Type" on the saved page.
Comment #15
StuartL CreditAttribution: StuartL commentedWas your initial event set to 'After saving new content'?
Comment #16
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedYes it was. See my last sentence in #14 :-)
Do you also get the options I have shown, or is your list completely different?
Comment #17
StuartL CreditAttribution: StuartL commentedMy list has some additional options. See attached screenshots.
Thanks,
Stuart
Comment #18
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedAh, yes, your screenshot does give something that is relevent here. I had noticed before that conditions in the "Other" section are not actually Rules conditions! This is why it does not work for you.
I had been meaning to raise this problem at some point, but now you have prompted me to do it. See #2927132: List of conditions includes Core conditions which do not work with Rules
Comment #19
StuartL CreditAttribution: StuartL commentedThanks - that helps clarify things. Unfortunately, I'm still not able to select the field when creating a redirect (action).
Comment #20
TR CreditAttribution: TR commentedMarked #2981784: Data selector doesn't show available fields as a duplicate.
Comment #21
Janner CreditAttribution: Janner commentedI am attempting to create a rule that will assign a role to a user based upon the status of a custom user field on the registration form and user edit page (in this case a boolean single checkbox).
Unfortunately, I have been unable to find a way of accessing this custom field when attempting to create a data comparison condition.
I have tried to make the field available by following other suggestions of adding conditions “Entity has field” and/or “Entity is of type” (and saved the rule before adding the data comparison condition).
This hasn't worked.
I have attempted to follow the suggestion offered in #11 here Finding custom fields & creating users - which is to add the condition that “Entity is of bundle”.
According to the suggestion, the values for Entity, Type, and Bundle should all be “user”. It's stated that the latter two values can be entered by Direct Input.
However, in my case, where I have patched the latest dev release of Rules to add support for select lists, both of those values use select lists with no option of switching to Direct Input.
For Type, “user” is available from the select list.
However, it is not available in the Bundle select list.
What am I missing or doing wrong? thanks
Comment #22
TR CreditAttribution: TR commentedIf you are having problems with #2664280: Select lists in action & condition configuration forms please discuss them in THAT issue, not here. Nothing in this issue has been on-topic since #2.