Commit 25fc6175 authored by tim.plunkett's avatar tim.plunkett

Issue #1781406 by tim.plunkett: Update views_dropbutton for the new direction of the core patch.

parent 30dda221
......@@ -5,8 +5,8 @@
*/
function views_dropbutton_theme($existing, $type, $theme, $path) {
return array(
'dropbutton' => array(
'variables' => array('title' => NULL, 'links' => array(), 'attributes' => array()),
'dropbutton_wrapper' => array(
'render element' => 'element',
),
);
}
......@@ -39,44 +39,44 @@ function views_dropbutton_library_info() {
}
/**
* Builds a render array for theme_dropbutton().
* Implements hook_element_info().
*/
function template_preprocess_dropbutton(&$variables) {
$variables['attributes']['class'][] = 'dropbutton';
$variables['element'] = array(
'#theme' => 'links',
'#links' => $variables['links'],
'#attributes' => $variables['attributes'],
'#attached' => array(
'library' => array(
array('views_dropbutton', 'drupal.dropbutton'),
),
),
function views_dropbutton_element_info() {
$types['dropbutton'] = array(
'#theme' => 'links__dropbutton',
'#pre_render' => array('drupal_pre_render_dropbutton'),
);
if (!empty($variables['links'])) {
$variables['element']['#prefix'] = '<div class="dropbutton-wrapper"><div class="dropbutton-widget">';
$variables['element']['#suffix'] = '</div></div>';
return $types;
}
/**
* Pre-render callback: Attaches the dropbutton library and required markup.
*/
function drupal_pre_render_dropbutton($element) {
$element['#attached']['library'][] = array('views_dropbutton', 'drupal.dropbutton');
$element['#attributes']['class'][] = 'dropbutton';
if (!isset($element['#theme_wrappers'])) {
$element['#theme_wrappers'] = array();
}
// Pass through title to the dropbutton options.
if (isset($variables['title'])) {
$variables['element']['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('dropbutton' => array('title' => $variables['title'])),
);
array_unshift($element['#theme_wrappers'], 'dropbutton_wrapper');
// Enable targeted theming of specific dropbuttons (e.g., 'operations' or
// 'operations__node').
if (isset($element['#subtype'])) {
$element['#theme'] .= '__' . $element['#subtype'];
}
return $element;
}
/**
* Creates a dropbutton menu.
* Returns HTML for wrapping a dropbutton menu.
*
* @param array $variables
* An associative array containing:
* - title: (optional) The text placed in the clickable area to activate the
* dropbutton. Defaults to 'Open dropbutton'.
* - links: An array of links to provide in the dropbutton.
* - attributes: (optional) An associative array of HTML attributes to apply
* to the dropbutton.
* - element: An associative array containing the properties and children of
* the dropbutton menu. Properties used: #children.
*/
function theme_dropbutton($variables) {
return render($variables['element']);
function theme_dropbutton_wrapper($variables) {
return '<div class="dropbutton-wrapper"><div class="dropbutton-widget">' . $variables['element']['#children'] . '</div></div>';
}
......@@ -139,8 +139,9 @@ public function buildOperations(EntityInterface $entity) {
}
}
// Use theme_dropbutton().
$build['#theme'] = 'dropbutton';
// Use the dropbutton #type.
unset($build['#theme']);
$build['#type'] = 'dropbutton';
return $build;
}
......
......@@ -180,10 +180,13 @@ public function getDisplayDetails($display) {
// The Delete, Duplicate and Undo Delete buttons.
$build['top']['actions'] = array(
'#prefix' => '<div class="dropbutton-wrapper"><div class="dropbutton-widget"><ul class="dropbutton">',
'#suffix' => '</ul></div></div>',
'#theme_wrappers' => array('dropbutton_wrapper'),
);
// Because some of the 'links' are actually submit buttons, we have to
// manually wrap each item in <li> and the whole list in <ul>.
$build['top']['actions']['prefix']['#markup'] = '<ul class="dropbutton">';
if (!$is_display_deleted) {
if (!$is_enabled) {
$build['top']['actions']['enable'] = array(
......@@ -249,6 +252,7 @@ public function getDisplayDetails($display) {
"#suffix" => '</li>',
);
}
$build['top']['actions']['suffix']['#markup'] = '</ul>';
// The area above the three columns.
$build['top']['display_title'] = array(
......@@ -385,7 +389,7 @@ public function renderDisplayTop($display_id) {
// Extra actions for the display
$element['extra_actions'] = array(
'#theme' => 'dropbutton',
'#type' => 'dropbutton',
'#attributes' => array(
'id' => 'views-display-extra-actions',
),
......@@ -950,11 +954,12 @@ public function getFormBucket($type, $display) {
}
// Render the array of links
$build['#actions'] = theme('dropbutton',
array(
'links' => $actions,
$build['#actions'] = array(
'#type' => 'dropbutton',
'#links' => $actions,
'#attributes' => array(
'class' => array('views-ui-settings-bucket-operations'),
)
),
);
if (!$this->displayHandlers[$display['id']]->isDefaultDisplay()) {
......
......@@ -51,7 +51,7 @@ function template_preprocess_views_ui_display_tab_bucket(&$variables) {
$variables['content'] = $element['#children'];
$variables['title'] = $element['#title'];
$variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : '';
$variables['actions'] = !empty($element['#actions']) ? render($element['#actions']) : '';
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment