Skip to content

Instantly share code, notes, and snippets.

@heddn
Created January 29, 2013 12:54
Show Gist options
  • Select an option

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

Select an option

Save heddn/4664017 to your computer and use it in GitHub Desktop.
Example of some recent work
/**
* 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 service detail 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;
}
/**
* Implements hook_theme().
*/
function example_theme() {
return array(
'example_brightcove' => array(
'variables' => array(
'height',
'width',
'playerID',
'@videoPlayer',
'attributes'
),
),
'example_flickr_set_slideshow' => array(
'variables' => array(
'set_id',
'attributes'
),
),
);
}
/**
* Theme callback for brightcove videos
*/
function theme_example_brightcove($variables) {
$attributes = $variables['attributes'];
$parameters = array(
'bgcolor' => '#FFFFFF',
'width' => '300',
'height' => '217',
'playerID' => '10987654321',
'playerKey' => 'AQ~~,AAAAwXeOQqE~,AGDFDSHafasseDGDdsaase',
'isVid' => 'true',
'dynamicStreaming' => 'true',
'wmode' => 'transparent',
'@videoPlayer' => '',
);
if (isset($variables['width'])) {
$parameters['width'] = $variables['width'];
}
if (isset($variables['height'])) {
$parameters['height'] = $variables['height'];
}
if (isset($variables['playerID'])) {
$parameters['playerID'] = $variables['playerID'];
}
if (isset($variables['@videoPlayer'])) {
$parameters['@videoPlayer'] = $variables['@videoPlayer'];
}
$parameter_html = '';
foreach ($parameters as $key => $value) {
$parameter_html .= "\t<param name='" . $key . "' value='" . $value . "' />" . PHP_EOL;
}
$output = '<div' . drupal_attributes($attributes) . ' style="display:none"></div>' . PHP_EOL;
$output .= '<object class="BrightcoveExperience" id="';
$output .= drupal_html_id('myExperience') . '">' . PHP_EOL . $parameter_html . '</object>' . PHP_EOL;
$output .= '<script type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>'
. PHP_EOL;
$output .= '<script type="text/javascript">brightcove.createExperiences();</script>';
return $output;
}
/**
* Theme callback for rendering a flickr slideshow.
*/
function theme_exampleflickr_set_slideshow($variables) {
$attributes = $variables['attributes'];
$output = "<div" . drupal_attributes($attributes) . " >" . PHP_EOL;
$output .= "<iframe align='center' src='http://www.flickr.com/slideShow/index.gne?set_id=";
$output .= $variables['set_id'];
$output .= "' frameBorder='0' width='300' height='220' scrolling='no'></iframe>" . PHP_EOL;
$output .= "</div>";
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment