brightcove_field.browse.inc in Brightcove Video Connect 7.6
Same filename and directory in other branches
Holds a method to list all BC videos that are attachable to a field.
File
brightcove_field.browse.incView source
<?php
/**
* @file
* Holds a method to list all BC videos that are attachable to a field.
*/
/**
* This function is a callback for modalframe window, providing an access to browse videos.
*
* @see brightcove_field_menu()
*
* @param string $entity_type
* @param string $field_name
* @param string $entity_id_or_bundle
* @param Entity $client
*
* @return string A list of available videos that can be attached to a field.
*/
function brightcove_field_browse($entity_type, $field_name, $entity_id_or_bundle, $client) {
module_load_include('inc', 'brightcove', 'brightcove_field.video');
$content = _brightcove_field_video_browse($client);
$content['filter_form']['css_and_js'] = [
'#type' => 'container',
'#attached' => [
'js' => [
drupal_get_path('module', 'brightcove') . '/js/brightcove.js',
ctools_attach_js('ajax-responder'),
],
'css' => [
drupal_get_path('module', 'brightcove') . '/styles/browse.css',
],
],
];
return '<div class="brightcove-browse-table">' . drupal_render($content['filter_form']) . $content['pager'] . theme('brightcove_field_browse_items', [
'items' => $content['items'],
'entity_type' => $entity_type,
'field_name' => $field_name,
'entity_id_or_bundle' => $entity_id_or_bundle,
'bcid' => $client->bcid,
]) . $content['pager'] . '</div>';
}
/**
* Menu callback for brightcove_field/autocomplete.
*
* @param $field_name
* Field name - field name that is requesting autocomplete. Unused, will be utilized to limit access to certain videos for certain fields.
* @param $client
* The client entity object.
* @param $string
* String to search for - will match videos by this text.
* @return
* JSON object with matched videos.
*/
function brightcove_field_autocomplete($type, $field_name, $client, $string = '') {
$matches = [];
$result = [];
switch ($type) {
case 'video':
brightcove_try(function () use (&$result, $client, $string) {
/** @var \Brightcove\API\CMS $cms */
list($cms, ) = brightcove_create_classes($client);
$result = $cms
->listVideos($string);
});
break;
case 'playlist':
// TODO implement if needed
$result = [];
break;
}
foreach ((array) $result as $bc_item) {
// Note: Brightcove ID is autogenerated by Brightcove and thus doesn't require XSS protection.
$matches[check_plain($bc_item->name) . ' [id:' . $bc_item->id . ']'] = check_plain($bc_item->name) . ' [id: ' . $bc_item->id . ']';
}
drupal_json_output($matches);
}
Functions
Name | Description |
---|---|
brightcove_field_autocomplete | Menu callback for brightcove_field/autocomplete. |
brightcove_field_browse | This function is a callback for modalframe window, providing an access to browse videos. |