From 25fc6175bdb2256aa0903e567b3af84cd0cbb659 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Tue, 2 Oct 2012 15:02:38 -0400 Subject: [PATCH] Issue #1781406 by tim.plunkett: Update views_dropbutton for the new direction of the core patch. --- views_dropbutton/views_dropbutton.module | 62 +++++++++---------- .../Drupal/views_ui/ViewListController.php | 5 +- views_ui/lib/Drupal/views_ui/ViewUI.php | 19 +++--- views_ui/theme/theme.inc | 2 +- 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/views_dropbutton/views_dropbutton.module b/views_dropbutton/views_dropbutton.module index c4dd08efb19a..48765dcad0e1 100644 --- a/views_dropbutton/views_dropbutton.module +++ b/views_dropbutton/views_dropbutton.module @@ -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>'; } diff --git a/views_ui/lib/Drupal/views_ui/ViewListController.php b/views_ui/lib/Drupal/views_ui/ViewListController.php index 6e388f233555..b4780cc3cc3b 100644 --- a/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -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; } diff --git a/views_ui/lib/Drupal/views_ui/ViewUI.php b/views_ui/lib/Drupal/views_ui/ViewUI.php index 565dbf98c2c2..fcd5d2f1a46a 100644 --- a/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -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()) { diff --git a/views_ui/theme/theme.inc b/views_ui/theme/theme.inc index c4dda8a4b83c..72d513f4a6f1 100644 --- a/views_ui/theme/theme.inc +++ b/views_ui/theme/theme.inc @@ -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']) : ''; } /** -- GitLab