Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How to get node field values and include it the Rules Action? If I have a custom content type that has taxonomy terms, and I want to display these terms in Action. Example output is simply logging the terms.
Event: content type is created
Condition: of node type: custom_content
Action: Log the taxonomy terms
Pseudo code:
public function execute() {
$term1 = field_taxonomy1_fromCustomContentType
$term2 = field_taxonomy2_fromCustomContentType
$this->setProvidedValue('concatenated', $term1 . $term2);
\Drupal::logger('custom_rules')->notice("Rules Action");
}
Comments
Comment #2
TR CreditAttribution: TR commentedAre you asking for someone to write your code for you? You don't explain what issue you're having. Accessing field values on a node is a core Drupal function (not Rules-specific), and there's lots of core documentation on how to do that, if that's what you don't understand. Perhaps you should try to write the code for your action then post it here if it doesn't work. There are many examples in src/Plugin/RulesAction that you can use as a start. This seems to be a pretty straightforward task to me.
Comment #3
johnreytanquinco CreditAttribution: johnreytanquinco commentedHi TR, thanks for your response. My goal is to get the taxonomy term name from the node. This is my simple Rules Action to hopefully display the field
field_pattern_type
, but getting error message.Error
Comment #4
TR CreditAttribution: TR commentedYou need a context definition in your class annotation, in order to specify what arguments are needed to be passed into the action and what their datatypes are. Your annotation should look something like this:
Comment #5
johnreytanquinco CreditAttribution: johnreytanquinco commentedThanks TR. That works as expected. Now, how can I output the field value, specifically I want to access taxonomy term of the node created.
I tried this for getting the value.
But the result in log is
Array
BTW, for my ENTITY, I select
node
in the Data selector.Comment #6
TR CreditAttribution: TR commentedComment #7
johnreytanquinco CreditAttribution: johnreytanquinco commentedWow! Thank you very much TR! I really appreciate your helping hand! :) Im new to php so im still trying my best to understand these functionalities.
Comment #8
johnreytanquinco CreditAttribution: johnreytanquinco commented