Skip to content

Instantly share code, notes, and snippets.

@heddn
Last active December 15, 2015 19:29
Show Gist options
  • Select an option

  • Save heddn/5312280 to your computer and use it in GitHub Desktop.

Select an option

Save heddn/5312280 to your computer and use it in GitHub Desktop.
/**
* Block call back for a media block.
*/
function example_block_media($entity = NULL, $child_title = NULL) {
$block = array();
$wrapper = empty($entity) ? entity_metadata_wrapper('node', menu_get_object()) : $entity;
if ($wrapper->type->value() == 'parent' || $wrapper->type->value() == 'child') {
if ($value = $wrapper->field_video_embed_code->value(array(
'sanitize' => TRUE
))) {
$block['content'] = theme('example_brightcove', array(
'@videoPlayer' => $value[0],
'videoID' => '1234567910',
'attributes' => array(
'class' => 'example-media',
),
));
}
elseif ($value = $wrapper->field_flickr->value(array(
'sanitize' => TRUE
))) {
$block['content'] = theme('example_flickr_set_slideshow', array(
'set_id' => $value,
'attributes' => array(
'class' => 'example-media',
),
));
}
elseif ($wrapper->field_files->value()) {
$description = $wrapper->field_files[0]->description->value() !== '' ? $wrapper->field_files[0]->description->value()
: $description = $wrapper->title->value();
// If we call recursively, and no description is set, then use the title of the child
if (isset($child_title) && $wrapper->field_files[0]->description->value() == '') {
$description = $child_title;
}
$description = filter_xss($description);
$block['content'] = theme('image', array(
'path' => $wrapper->field_files[0]->file->url->value(),
'alt' => $description,
'title' => $description,
'width' => '300px',
'height' => '220px',
'attributes' => array(
'class' => 'example-media',
),
));
}
elseif ($wrapper->type->value() == 'child') {
// Pass in the title of the child node to use as the title/alt
// text of the image (in case one wasn't set).
// field_parent_node_ref is a required field on child content type.
$block = example_block_media($wrapper->field_parent_node_ref, $wrapper->title->value());
}
}
return $block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment