Created
October 7, 2014 09:37
-
-
Save stemount/fc475f54b74661bf270d to your computer and use it in GitHub Desktop.
Drupal Brightcove Token Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Brightcove Node Embed | |
description = Provides a simple input filter to use [[brightcode:VIDEO_ID]] to insert a Brightcove video on a node. | |
core = 7.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_filter_info() | |
*/ | |
function brightcove_embed_filter_info() { | |
$filters['brightcove_embed'] = array( | |
'title' => t('Embed Brightcove videos'), | |
'description' => t('Use syntax [[brightcove:VIDEO_ID]] to embed an inline Brightcove video'), | |
'process callback' => '_brightcove_embed_process_callback', | |
'tips callback' => '_brightcove_embed_process_filter_tips', | |
'cache' => FALSE, | |
); | |
return $filters; | |
} | |
/** | |
* Implements hook_theme(). | |
*/ | |
function brightcove_embed_theme() { | |
return array( | |
'brightcove_embed_video' => array( | |
'template' => 'templates/brightcove_video', | |
'variables' => array('video_id' => NULL, 'playerID' => NULL, 'playerKey' => NULL), | |
), | |
); | |
} | |
/** | |
* Process callback for hook_filter | |
*/ | |
function _brightcove_embed_process_callback($text, $filter, $format, $langcode, $cache, $cache_id) { | |
return preg_replace_callback('/\[\[brightcove:(\d+)(\s.*)?\]\]/', '_brightcove_embed_build_video', $text); | |
} | |
/** | |
* Provide tips for hook_filter | |
*/ | |
function _brightcove_embed_process_filter_tips($filter, $format) { | |
return t('Use [[brightcove:VIDEO_ID]] to insert an inline brightcove video'); | |
} | |
/** | |
* Build video player | |
*/ | |
function _brightcove_embed_build_video($matches) { | |
// Check if video ID provided via node entry magic syntax is a valid number. | |
if (is_numeric($matches[1])) { | |
// Add Brightcove Experiences API and BeginExperiences callback | |
drupal_add_js('//admin.brightcove.com/js/BrightcoveExperiences.js', array('type' => 'external', 'scope' => 'footer')); | |
drupal_add_js('brightcove.createExperiences();', array('type' => 'inline', 'scope' => 'footer')); | |
// Add Brightcove Embed CSS to make the player render a responsive video | |
drupal_add_css(drupal_get_path('module', 'brightcove_embed') . '/css/brightcove_embed.css'); | |
return theme('brightcove_embed_video', array('video_id' => $matches[1], 'playerID' => 1414283948001, 'playerKey' => 'AQ~,AAAAAGqBXh8,uLHkVFEJ0O2qQwkxx0amJt-eXY78W5gb')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[brightcove:3811542772001]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment