1

I've got a contenttype "gallery" with an imagefield "thumbnail", used in listviews oder teaserviews. This contenttype also has a field collection with "image", "title" and "description". So what would be great now, if there's no value set for the "thumbnail" field, the default value should be the value from the first field-collection image.

any chance to realize this? Thanks for your help

EDIT:

i tried this:

That's not a solution

function channelportal_gallery_node_presave($node) {

    $galleryimage = field_get_items('node', $node, 'field_gallery_and_caption');
    $firstimageID = $galleryimage[0]['value'];

    $item = field_collection_item_load($firstimageID);
    dpm($node->field_thumbnail);

    $node->field_thumbnail = field_get_items('field_collection_item', $item, 'field_gallery_image');
    dpm($node->field_thumbnail);
}

But nothing is stored, to the field, even if the first dpm gives back an empty array and the second one containing the values it should contain. But after all, nothing is stored to the field and it's empty again...

Thanks for your answer Chad Payne

0

I would look in to something like

hook_node_presave

As a rough example I would have it work like this

function MY_MODULE_node_presave($node) {
     if(!isset($node->field_thumbnail)) {
          // load field collection and save that image to this image field
     }
}

I haven't tested this code but i think this would be the direction you would want to go in.

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.