insert_video.module in Insert Video 7
Insert support for Media module.
File
insert_video.moduleView source
<?php
/**
* @file
* Insert support for Media module.
*/
/**
* Implements hook_theme().
*/
function insert_video_theme() {
return array(
'video_insert_video' => array(
'variables' => array(
'item' => NULL,
'style' => NULL,
'widget' => NULL,
),
'template' => 'templates/video-insert-video',
'pattern' => 'video_insert_video[a-z0-9_]+',
),
);
}
/**
* Implementation of hook_insert_widgets().
*/
function insert_video_insert_widgets() {
return array(
'media_multiselect' => array(
'element_type' => 'media',
'wrapper' => '.media-widget',
'fields' => array(
'description' => 'input[name$="[description]"], textarea[name$="[description]"]',
),
),
'media_generic' => array(
'element_type' => 'media',
'wrapper' => '.media-widget',
'fields' => array(
'description' => 'input[name$="[description]"], textarea[name$="[description]"]',
),
),
);
}
/**
* Implementation of hook_insert_styles().
*/
function insert_video_insert_styles() {
$formatters = insert_video_formatters(NULL, TRUE);
$insert_styles = array();
foreach ($formatters as $name => $formatter) {
$insert_styles[$name] = array(
'label' => t($formatter['label']),
);
}
return $insert_styles;
}
/**
* Implementation of hook_insert_content().
*
* Just pass through to the theme function.
*/
function insert_video_insert_content($item, $style, $widget) {
return theme('video_insert_video', array(
'item' => $item,
'style' => $style,
'widget' => $widget,
));
}
/**
* Theme the content that will be inserted for Video.
*/
function template_preprocess_video_insert_video(&$vars) {
$vars['file'] = file_load($vars['item']['fid']);
$formatter = insert_video_formatters($vars['style']['name']);
$func = $formatter['view callback'];
// Create an array of arguments to pass to the formatter's view hook.
$args = array(
'file' => $vars['file'],
'display' => array(
'settings' => $formatter['default settings'],
),
'langcode' => NULL,
);
$vars['element'] = call_user_func_array($func, $args);
$vars['video'] = render($vars['element']);
$absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
$vars['url'] = file_create_url($vars['file']->uri, $absolute, variable_get('clean_url'));
$vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
}
/**
* Build a list of available formatters.
*/
function insert_video_formatters($key = NULL, $refresh = FALSE) {
$formatters =& drupal_static(__FUNCTION__, array());
// Return our cached id if allowed, and it exists.
if (!$refresh && $key && isset($formatters[$key])) {
return $formatters[$key];
}
elseif (!$refresh && $key && !isset($formatters[$key])) {
return $formatters;
}
$formatters = file_info_formatter_types();
foreach ($formatters as $name => $formatter) {
if (!isset($formatter['file types']) || !in_array('video', $formatter['file types'])) {
unset($formatters[$name]);
}
}
return !isset($formatters[$key]) ? $formatters : $formatters[$key];
}
Functions
Name![]() |
Description |
---|---|
insert_video_formatters | Build a list of available formatters. |
insert_video_insert_content | Implementation of hook_insert_content(). |
insert_video_insert_styles | Implementation of hook_insert_styles(). |
insert_video_insert_widgets | Implementation of hook_insert_widgets(). |
insert_video_theme | Implements hook_theme(). |
template_preprocess_video_insert_video | Theme the content that will be inserted for Video. |