class BrightcovePlaylistEntityUIController in Brightcove Video Connect 7.6
Same name and namespace in other branches
- 7.7 brightcove.playlist.inc \BrightcovePlaylistEntityUIController
Entity UI Controller class for brightcove playlists.
Hierarchy
- class \EntityDefaultUIController
Expanded class hierarchy of BrightcovePlaylistEntityUIController
1 string reference to 'BrightcovePlaylistEntityUIController'
- brightcove_entity_info in ./
brightcove.module - Implements hook_entity_info().
File
- ./
brightcove.playlist.inc, line 136 - Brightcove playlist related functions.
View source
class BrightcovePlaylistEntityUIController extends EntityBundleableUIController {
private $form_state;
public function hook_menu() {
$items = parent::hook_menu();
$items['admin/config/media/brightcove/playlist'] = [
'type' => MENU_LOCAL_TASK,
'title' => 'Playlists',
'page callback' => 'drupal_get_form',
'page arguments' => [
$this->entityType . '_overview_form',
$this->entityType,
],
'description' => 'Manage playlists.',
'access callback' => 'entity_access',
'access arguments' => [
'view',
$this->entityType,
],
'file' => 'includes/entity.ui.inc',
];
return $items;
}
/**
* Overrides EntityDefaultUIController::overviewForm()
*/
public function overviewForm($form, &$form_state) {
$this->form_state = $form_state;
module_load_include('inc', 'brightcove', 'brightcove.client');
$form['bcid'] = brightcove_client_select_element();
$wrapper_id = 'bc-playlists';
if (!isset($form['bcid']['#type'])) {
return $form;
}
switch ($form['bcid']['#type']) {
case 'select':
$form['bcid']['#ajax'] = [
'wrapper' => $wrapper_id,
'callback' => 'brightcove_playlist_tables_ajax_callback',
];
$form['bcid']['#ajax_id'] = 'bc_client_select';
$client_id = filter_input(INPUT_GET, 'client', FILTER_SANITIZE_NUMBER_INT);
if (!empty($client_id) && (!isset($form_state['triggering_element']['#ajax_id']) || isset($form_state['triggering_element']['#ajax_id']) && $form_state['triggering_element']['#ajax_id'] != 'bc_client_select')) {
$bcid = $client_id;
}
else {
$bcid = isset($form_state['values']['bcid']) ? $form_state['values']['bcid'] : $form['bcid']['#default_value'];
}
if (!empty($client_id)) {
$form['bcid']['#default_value'] = $bcid;
}
break;
case 'value':
$bcid = $form['bcid']['#value'];
break;
default:
return $form;
}
$form['playlists'] = [
'#prefix' => '<div id="' . $wrapper_id . '">',
'#suffix' => '</div>',
];
if (!empty($bcid) && $bcid != BRIGHTCOVE_BCID_NONE) {
$client = brightcove_client_load($bcid);
$form['playlists']['#markup'] = $this
->overviewTable([
'client' => $client,
]);
}
return $form;
}
/**
* Renders the playlist overview table.
*
* @return string
* Rendered overivew page.
*/
public function overviewTable($conditions = []) {
$client = $conditions['client'];
$table = [
'header' => [
t('ID'),
t('Title'),
[
'colspan' => 2,
'data' => t('Operations'),
],
],
];
module_load_include('inc', 'brightcove', 'brightcove.playlist');
$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT);
if (empty($page)) {
$page = 0;
}
$playlists = brightcove_get_playlists($client, 'name', $page);
if ($playlists) {
foreach ($playlists as $playlist) {
$playlist_entity_id = $playlist
->getId() . '-' . $client->bcid;
$playlist_entity = brightcove_playlist_load($playlist_entity_id);
$table['rows'][] = $this
->overviewRow($playlist_entity);
}
}
else {
$table['rows'][] = [
[
'data' => t('No playlist found.'),
'colspan' => count($table['header']),
],
];
}
// Restore original url for the pager.
if (isset($this->form_state['complete form']['#action'])) {
$action = $this->form_state['complete form']['#action'];
$qmark_pos = strripos($action, '?');
$_GET['q'] = $qmark_pos !== FALSE ? substr($action, 0, $qmark_pos) : substr($action, 0);
}
pager_default_initialize(_brightcove_playlist_items_total($client), variable_get('brightcove_pager_max_items', 20), 0);
return theme('table', $table) . theme('pager', [
'parameters' => [
'client' => $client->bcid,
],
]);
}
/**
* Renders a table row on the Brightcove playlist overview page.
*
* @param Entity $playlist
* The playlist entity object.
*
* @return array
* Table row.
* @see theme_table()
*/
protected function overviewRow(Entity $playlist) {
return [
$playlist->playlist
->getId(),
$playlist->playlist
->getName(),
l(t('edit'), "admin/config/media/brightcove/playlist/{$playlist->bpid}/edit"),
l(t('delete'), "admin/config/media/brightcove/playlist/{$playlist->bpid}/delete"),
];
}
/**
* Override operationFormSubmit().
*
* @param $form
* @param $form_state
*/
public function operationFormSubmit($form, &$form_state) {
parent::operationFormSubmit($form, $form_state);
// Redirect back to the playlist after submit.
$form_state['redirect'] = 'admin/config/media/brightcove/playlist';
$form_state['rebuild'] = FALSE;
}
}