0

Let's say I have a Structure Content type called "Fruit", and it only has a title.

And I have another Structure Content type called "Color" which is a dropdown menu with a few colors in it.

And i have an "entity reference" for Color on Fruit. So when I go to add a new Fruit, I can input in the Fruit title field "Apple", and then choose from the Color dropdown menu "Red".

I have a hook for node_update() which triggers when I change the Title of the Fruit. But when I change the Color, this trigger is not executed.

Which hook should I use if I want to track the Color changing on a Fruit?

This is for Drupal 7. Thanks so much in advance for your time and insight.

1 Answer 1

1

You don't have a direct connection for those(the same way some entities work at least) so best approach would be to have a node_update for Color and then inside it to query (can use entityQuery) and see which fruits have that color, from here you can do your stuff.

the following pulled out of my head since I haven't touch D7 for over a year so here we go

function node_update($node){
  if($node['type'] == 'color'){
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'fruit')
    //value or target_id
    ->fieldCondition('field_photo', 'value', $node['nid']); 

    $result = $query->execute();
  }
}
3
  • Thanks so much - this is a pretty good solution that makes sense to me and is feasible. Do you know how I can reference the parent node from within the entity update hook?
    – Armin
    Commented Apr 22, 2018 at 19:46
  • updated my answer Commented Apr 22, 2018 at 19:51
  • Unfortunately the EntityFieldQuery isn't a viable option. This doesn't allow me to access the dropdown menu option color itself (Red, Green, etc). I only have access to thousands of results worth of vid's and nid's of the same type (Color), but no actual valuable information What I want is to know the previous color, and the new color if a Fruit is updated, and the Fruit node ID that was updated.
    – Armin
    Commented Apr 22, 2018 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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