How do I access the user fields?

Created on 8 January 2022, almost 3 years ago
Updated 11 April 2023, over 1 year ago

I'm trying to make a rule that updates a user field after that user creates a node. However, I can't seem to access the user fields.

I've setup an "Entity is of bundle" condition that uses @user.current_user_context:current_user as the entity and 'user' as the type and bundle. I've seen suggestions that you can use "user" as the entity, but my rules doesn't let me use anything less than @user.current_user_context:current_user.

When I create an action, I can't seem to access any of the user fields. Hard finding much documentation that covers this issue.

πŸ’¬ Support request
Status

Active

Component

Rules Core

Created by

πŸ‡ΊπŸ‡ΈUnited States arlingtonvoicellc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    @All,

    I was able to figure out how to get the rules_user_fields module to retrieve custom fields from the 'Actions' however after following all the available threads on stack exchange and drupal.org I was unable to figure out how to do this from the 'Conditions' for a data comparison.

    In the Actions I had to create a variable from the retrieved value of the fetched entity and set it as an integer

    However I haven't found a way to access custom fields from a user entity in the 'Conditions'

    The rules_user_fields module functionality appears to only be available from the 'Actions'. If I figure this out I'll update this thread.

  • πŸ‡ΊπŸ‡ΈUnited States arlingtonvoicellc

    In case anyone is interested, I resolved this issue by switching to the ECA module, which appears to be better maintained and with more robust features than rules. Highly recommend making the switch.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    @arlingtonvoicellc, ECA looks like a very interesting project and is progressing rapidly. With that said, rules is mature, has far more existing installations and supports PHP 8.0. The latest ECA requires a minimum PHP 8.1 and is going through intense development.

  • πŸ‡ΊπŸ‡ΈUnited States arlingtonvoicellc

    The most current version of Rules is still in an "Alpha" release state, while ECA has a stable release for the most current version of Drupal. So your characterization of "intense development" could easily be cast back at Rules for still being in Alpha state all these years later. Support for Rules is largely dead and left to each individual to figure out, without waiting months for a ping from the community. ECA has a stable release for the current version of Drupal and has a very active developer community that rapidly responds to tickets. I'd imagine most of the rules installations are attributed to Drupal 7 websites. Rules worked on Drupal 7. I don't know why so much changed with Drupal 8, but it doesn't work like it did. ECA is an incredibly robust module that does everything Rules should do plus more. I'd encourage anybody to give it a shot with the expectation of phasing out Rules.

  • Status changed to Closed: outdated over 1 year ago
  • Status changed to Active over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
  • πŸ‡ΊπŸ‡ΈUnited States arlingtonvoicellc

    Stating the truth is not "false statements" and "hateful speech." Not knowing the background of the rift, I'd guess your attitude is probably why some devs jumped ship and started ECA. On the contrary, a post in the ECA forum is met with enthusiasm and a helpful attitude. Have a fair day. Good luck with rules. I have abandoned using it. I have nothing more to add here.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    We've had success in this use case with a custom user field:

    Commerce module
    Auction module that integrates with commerce
    Rules module
    rules_user_fields module

    Custom user field called "bids remaining" of type "float/integer/text" .

    For every auction bid placed, I've configured rules to decrement the remaining bids field.

    Every time a bid is saved, we have configured a rule to load the user entity by the user associated with the bid and then access the user field value in the actions.

    In the actions I'm able to load the user field using the rules_user_fields module when this module is installed.

    This works as I've configured it, so for the moment I don't require the user field to be available in the conditions although that would be great if it was available.

    Basically the bids remaining is decremented by the actions we added to the rules configuration. It's working.

    We could have done all this in a bid presave hook or some other bid event with custom PHP but decided to try out rules and did manage to figure it out for learning purposes.

    Very cool module, thanks @TR

Production build 0.71.5 2024