0

In Rules 8, I know how to make custom fields of a content type accessible in an event "After updating a content item (rules_entity_update:node)", that is:

Condition: Entity is of bundle
Entity: node
Type: node
Bundle: my_content_type

So that I can use something like {{node.my_custom_field.value}}.

But, when I'm in an event "After saving a new comment (rules_entity_insert:comment)", the above solution does not work. How should I do to access custom fields of the node the comment is attached to?

0

Couldn't find an answer using Rules, and ended up adding some code:

function my-module_comment_insert(Drupal\Core\Entity\EntityInterface $entity)
{
   // Get NID and load Node
   $nid = $entity->get('entity_id')->target_id;
   $node = \Drupal\node\Entity\Node::load($nid);
}

From there I can use $node->get('field_something'). Of course if it's an entity reference field (as per my case), there's some work to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.