2

Working with Drupal 8.4.5 and Rules 8.x-3.0-alpha3 and Typed Data 8.x-1.0-alpha1

With Drupal 7 Rules, we may use an user custom field for data comparison (address or vocabulary for example). And it was easy to create the condition Entity has field with a select list to choose the right field (cf screenshot) : enter image description here

Now, in Drupal 8 Rules, the procedure has changed and I did not manage to reproduce this simple condition Entity has field since the Field select list has disappeared and custom fields are hidden in the Data selector suggestions (cf screenshot)

enter image description here

So my question is : how to use my custom field in a Rule (simple data comparison, for example)? What is the new way to write user:field_custom?

Surprisingly, the help text within Entity has field condition says : ...To make entity fields appear in the data selector, you may have to use the condition 'entity has field'...

It seems like an infinite loop to me?

Furthermore, "More useful tips about data selection is available in the online documentation" and there we have documentation about Drupal 7 Rules.

Ultimately, I need to create a Rule in Drupal 8 to automatically give an user role when a new account is saved, depending on a custom field value.

The question below is quite similar.

How to custom field has a value with the Rules module?

EDIT : I found an alternative for my specific need with the module Auto User Role (still in dev version). It seems to work nicely (only when saving a new user, not after editing an user, so the custom field is required at creation)

2 Answers 2

1

... since the Field select list has disappeared and custom fields are hidden in the Data selector suggestions.

The above is a partial quote of your question. IMO that's not correct. Instead it should say "... since the Field select list does not appear yet and custom fields are not shown yet in the Data selector suggestions".

And similar to the (my) answer to the question you linked to: those or some of the things that are still missing in the most recent D8 version of Rules. Refer to #d8rules status update November 2017 to get a better understanding of the current status of Rules for D8.

One never realizes what has been done, only what remains to be done ... So start here if you wonder how to contribute.

4
  • Bonjour @Pierre and thanks for your reply. My question was not a complaint but more a support request. I was not trying to say that Rules development is too slow or something close, because in my opinion, Rules is an absolute must-have for any Drupal website (should be in core actually) and I really want to use it in D8. So here I simply need help to use it the right way, as it is built today. My comments about the help texts were here to point that I have read carefully any documentation available before asking a question here.
    – Toki
    Mar 8, 2018 at 9:24
  • Bonjour @Toki ! Sure I understand your question is not a complaint. The sad news (I think) is that you seem to be struggling with rules in D8 like quite a few (many?) others do (consider at least me as one of them, so welcome to the party!). And yes I agree Rules is a must-have. Even more: for as long as there is no "stable" Rules for D8, "I" consider D8 as not production ready (similar to what happened iin Views in D7). That's because I cannot imagine any site with NO Rules enabled (not to forget all modules that have Rules as a dependency). Are we thinking similar about all this? Mar 8, 2018 at 9:30
  • Totally agree. Actually I thought that 2018 was the right time to start building with D8 and, even if I manage to build a few things, I am still struggling with "incomplete" modules (Rules, Panels, etc.). But I really want to use D8, we all need to go forward and to "get rid" of D7 habits ^^. Now, concerning my question, do you know how I can use in RulesD8 a custom field created for user profile?
    – Toki
    Mar 8, 2018 at 10:33
  • I don't know how to do such thing with the D8-alfa3 version of Rules. Though if you want to consider doing so, you might get closer to get it to work using the D8-dev version of Rules. Obviously, using a DEV version in a prod site is not something you should do, unless maybe if it is the only option/alternative left. Attention: I've not tried that (yet) myself, but if I was in your shoes (and desparate enough), that's what I would give a try. If you do, please let me know (extra comment?) the outcome of that. Bonne chance! Mar 8, 2018 at 10:49
1

To get access to user's custom fields from a condition you need first to add the 'Entity is of Bundle' condition. See the following tutorial: https://www.drupal.org/project/rules/issues/2912457#comment-12904391

But if you create a User in a Rule and want to get access to its custom fields from this Rule then you can use 'Rules User Fields' module.

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.