Alter field (multiple values) to add more items/values of another field In my case, I use Drupal Commerce (Kickstart 2x distribution) with a images field (multiples/unlimited values).

I need to display all images of parent product AND images of their childrens (variations).

Another case are to display images of a field but if empty, I want to display images of another images field.

What's the good way for this?


Relation module
hook_field_load()
hook_query_alter()
hook_node_load()
hook_load()




Related questions:

How to create a single slideshow combining several image fields?
Here my current solution but I think it is better to use hook_preprocess_field()?

/**
 * Implements hook_node_load().
 */
function MY_MODULE_entity_load($entities, $type){
    if('commerce_product' === $type &amp;&amp; !path_is_admin(current_path())){
        foreach($entities as $entity){
            if(in_array($entity-&gt;type, array('MY_PRODUCT_TYPE')) &amp;&amp; property_exists($entity, 'sku') &amp;&amp; !empty($entity-&gt;sku)){
                $query = new EntityFieldQuery;
                $query-&gt;entityCondition('entity_type', 'node', '=')
                  -&gt;propertyCondition('type', $entity-&gt;type)
                  -&gt;fieldCondition('field_product', 'product_id', $entity-&gt;product_id, '=')
                  -&gt;range(0, 1);

                if ($result = $query-&gt;execute()) {
                    reset($result['node']);
                    $nid = key($result['node']);
                    $parent_product = node_load($result['node'][$nid]-&gt;nid);
                    $parent_product_images = field_get_items('node', $parent_product, 'MY_IMAGES_FIELD');
                    if (is_array($parent_product_images)) {
                        $pos = count($entity-&gt;field_images['und']);
                        foreach($parent_product_images as $ppi_field){
                            $entity-&gt;field_images['und'][$pos++] = $ppi_field;
                        }
                    }
                }
            }
        }
    }
}