From 4daa01cb892a1b74e8c1239abfe1eca402a3db96 Mon Sep 17 00:00:00 2001
From: Tim Plunkett <git@plnktt.com>
Date: Tue, 7 Aug 2012 09:43:42 -0400
Subject: [PATCH] Issue #1716908 by aspilicious, tim.plunkett: Use the new
 attributes system in D8.

---
 css/views-admin.contextual.css                |  8 ++---
 .../views_handler_field_contextual_links.inc  |  4 +--
 includes/admin.inc                            | 11 +++----
 js/views-contextual.js                        |  2 +-
 tests/templates/views-view--frontpage.tpl.php | 16 +++++-----
 theme/theme.inc                               | 29 +++++++++----------
 theme/views-ui-display-tab-bucket.tpl.php     |  2 +-
 theme/views-ui-display-tab-setting.tpl.php    |  2 +-
 theme/views-view-grid.tpl.php                 |  2 +-
 theme/views-view-list.tpl.php                 |  2 +-
 theme/views-view-table.tpl.php                |  2 +-
 theme/views-view-unformatted.tpl.php          |  2 +-
 theme/views-view.tpl.php                      | 18 ++++++------
 views.module                                  |  6 ++--
 views_ui.module                               |  4 +--
 15 files changed, 52 insertions(+), 58 deletions(-)

diff --git a/css/views-admin.contextual.css b/css/views-admin.contextual.css
index 502e94947c45..fb2d09ca379d 100644
--- a/css/views-admin.contextual.css
+++ b/css/views-admin.contextual.css
@@ -5,16 +5,16 @@
 
 /* @group Wrapper */
 
-#views-live-preview .contextual-links-region-active {
+#views-live-preview .contextual-region-active {
   outline: medium none;
 }
 
-#views-live-preview div.contextual-links-wrapper {
+#views-live-preview div.contextual {
   right: auto;
   top: auto;
 }
 
-html.js #views-live-preview div.contextual-links-wrapper {
+html.js #views-live-preview div.contextual {
   display: inline;
 }
 
@@ -30,7 +30,7 @@ html.js #views-live-preview div.contextual-links-wrapper {
 
 /* @group List */
 
-div.contextual-links-wrapper ul.contextual-links {
+div.contextual ul.contextual-links {
   -moz-border-radius: 0 4px 4px 4px;
   -webkit-border-radius: 0 4px 4px 4px;
   border-radius: 0 4px 4px 4px;
diff --git a/handlers/views_handler_field_contextual_links.inc b/handlers/views_handler_field_contextual_links.inc
index 675c2f44e54b..86a057fb01e4 100644
--- a/handlers/views_handler_field_contextual_links.inc
+++ b/handlers/views_handler_field_contextual_links.inc
@@ -45,7 +45,7 @@ function options_form(&$form, &$form_state) {
 
   function pre_render(&$values) {
     // Add a row plugin css class for the contextual link.
-    $class = 'contextual-links-region';
+    $class = 'contextual-region';
     if (!empty($this->view->style_plugin->options['row_class'])) {
       $this->view->style_plugin->options['row_class'] .= " $class";
     }
@@ -85,7 +85,7 @@ function render($values) {
 
     if (!empty($links)) {
       $build = array(
-        '#prefix' => '<div class="contextual-links-wrapper">',
+        '#prefix' => '<div class="contextual">',
         '#suffix' => '</div>',
         '#theme' => 'links__contextual',
         '#links' => $links,
diff --git a/includes/admin.inc b/includes/admin.inc
index 0e57120ef3bb..9daaf32540d2 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -1801,14 +1801,11 @@ function template_preprocess_views_ui_display_tab_setting(&$variables) {
   array_unshift($variables['settings_links'], $variables['link']);
   $variables['settings_links'] = implode('<span class="label">&nbsp;|&nbsp;</span>', $variables['settings_links']);
 
-  // Add classes associated with this display tab to the overall list.
-  $variables['classes_array'] = array_merge($variables['classes_array'], $variables['class']);
-
   if (!empty($variables['defaulted'])) {
-    $variables['classes_array'][] = 'defaulted';
+    $variables['attributes']['class'][] = 'defaulted';
   }
   if (!empty($variables['overridden'])) {
-    $variables['classes_array'][] = 'overridden';
+    $variables['attributes']['class'][] = 'overridden';
     $variables['attributes_array']['title'][] = t('Overridden');
   }
 
@@ -1826,10 +1823,10 @@ function template_preprocess_views_ui_display_tab_bucket(&$variables) {
     $variables['item_help_icon'] = render($element['#item_help_icon']);
   }
   if (!empty($element['#name'])) {
-    $variables['classes_array'][] = drupal_clean_css_identifier(strtolower($element['#name']));
+    $variables['attributes']['class'][] = drupal_html_class($element['#name']);
   }
   if (!empty($element['#overridden'])) {
-    $variables['classes_array'][] = 'overridden';
+    $variables['attributes']['class'][] = 'overridden';
     $variables['attributes_array']['title'][] = t('Overridden');
   }
 
diff --git a/js/views-contextual.js b/js/views-contextual.js
index 2e9dcf7a6119..eda4794c194f 100644
--- a/js/views-contextual.js
+++ b/js/views-contextual.js
@@ -9,7 +9,7 @@ Drupal.behaviors.viewsContextualLinks = {
     // If there are views-related contextual links attached to the main page
     // content, find the smallest region that encloses both the links and the
     // view, and display it as a contextual links region.
-    $('.views-contextual-links-page', context).closest(':has(.view)').addClass('contextual-links-region');
+    $('.views-contextual-links-page', context).closest(':has(.view)').addClass('contextual-region');
   }
 };
 
diff --git a/tests/templates/views-view--frontpage.tpl.php b/tests/templates/views-view--frontpage.tpl.php
index eb4f58b7b58c..e9ae6b1c1876 100644
--- a/tests/templates/views-view--frontpage.tpl.php
+++ b/tests/templates/views-view--frontpage.tpl.php
@@ -5,14 +5,14 @@
  * Main view template.
  *
  * Variables available:
- * - $classes_array: An array of classes determined in
- *   template_preprocess_views_view(). Default classes are:
- *     .view
- *     .view-[css_name]
- *     .view-id-[view_name]
- *     .view-display-id-[display_name]
- *     .view-dom-id-[dom_id]
- * - $classes: A string version of $classes_array for use in the class attribute
+ * - $attributes: An instance of Attributes class that can be manipulated as an
+ *   array and printed as a string.
+ *   It includes the 'class' information, which includes:
+ *    .view
+ *    .view-[css_name]
+ *    .view-id-[view_name]
+ *    .view-display-id-[display_name]
+ *    .view-dom-id-[dom_id]
  * - $css_name: A css-safe version of the view name.
  * - $css_class: The user-specified classes names, if any
  * - $header: The view header
diff --git a/theme/theme.inc b/theme/theme.inc
index 2e61d684e2c6..5c5e8eea52f7 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -55,16 +55,16 @@ function template_preprocess_views_view(&$vars) {
   // Basic classes
   $vars['css_class'] = '';
 
-  $vars['classes_array'] = array();
-  $vars['classes_array'][] = 'view';
-  $vars['classes_array'][] = 'view-' . drupal_clean_css_identifier($vars['name']);
-  $vars['classes_array'][] = 'view-id-' . $vars['name'];
-  $vars['classes_array'][] = 'view-display-id-' . $vars['display_id'];
+  $vars['attributes']['class'] = array();
+  $vars['attributes']['class'][] = 'view';
+  $vars['attributes']['class'][] = 'view-' . drupal_clean_css_identifier($vars['name']);
+  $vars['attributes']['class'][] = 'view-id-' . $vars['name'];
+  $vars['attributes']['class'][] = 'view-display-id-' . $vars['display_id'];
 
   $css_class = $view->display_handler->get_option('css_class');
   if (!empty($css_class)) {
     $vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
-    $vars['classes_array'][] = $vars['css_class'];
+    $vars['attributes']['class'][] = $vars['css_class'];
   }
 
   $empty = empty($vars['rows']);
@@ -114,7 +114,7 @@ function template_preprocess_views_view(&$vars) {
     // each view. This identifier is written to both Drupal.settings and the DIV
     // wrapper.
     $vars['dom_id'] = $view->dom_id;
-    $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id'];
+    $vars['attributes']['class'][] = 'view-dom-id-' . $vars['dom_id'];
   }
 
   // If using AJAX, send identifying data about this view.
@@ -169,9 +169,6 @@ function template_process_views_view(&$vars) {
   if (is_array($vars['rows'])) {
     $vars['rows'] = drupal_render($vars['rows']);
   }
-
-  // Flatten the classes to a string for the template file.
-  $vars['classes'] = implode(' ', $vars['classes_array']);
 }
 
 /**
@@ -634,7 +631,7 @@ function template_preprocess_views_view_table(&$vars) {
     $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last';
   }
 
-  $vars['classes_array'] = array('views-table');
+  $vars['attributes']['class'] = array('views-table');
   if (empty($vars['rows']) && !empty($options['empty_table'])) {
     $vars['rows'][0][0] = $view->display_handler->render_area('empty');
     // Calculate the amounts of rows with output.
@@ -645,9 +642,9 @@ function template_preprocess_views_view_table(&$vars) {
 
   if (!empty($options['sticky'])) {
     drupal_add_js('misc/tableheader.js');
-    $vars['classes_array'][] = "sticky-enabled";
+    $vars['attributes']['class'][] = "sticky-enabled";
   }
-  $vars['classes_array'][] = 'cols-'. count($vars['header']);
+  $vars['attributes']['class'][] = 'cols-'. count($vars['header']);
 
   if (!empty($handler->options['summary'])) {
     $vars['attributes_array'] = array('summary' => $handler->options['summary']);
@@ -666,6 +663,7 @@ function template_preprocess_views_view_grid(&$vars) {
   $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : TRUE;
 
   $columns  = $options['columns'];
+  $vars['attributes']['class'][] = 'views-view-grid cols-' . $columns;
 
   $rows = array();
   $row_indexes = array();
@@ -761,7 +759,6 @@ function template_preprocess_views_view_grid(&$vars) {
     }
   }
   $vars['rows'] = $rows;
-  $vars['class'] = 'views-view-grid cols-' . $columns;
   if (!empty($handler->options['summary'])) {
     $vars['attributes_array'] = array('summary' => $handler->options['summary']);
   }
@@ -776,7 +773,7 @@ function template_preprocess_views_view_unformatted(&$vars) {
   $style = $view->style_plugin;
   $options = $style->options;
 
-  $vars['classes_array'] = array();
+  $vars['row_classes'] = array();
   $vars['classes'] = array();
   $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
   $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : FALSE;
@@ -804,7 +801,7 @@ function template_preprocess_views_view_unformatted(&$vars) {
     }
 
     // Flatten the classes to a string for each row for the template file.
-    $vars['classes_array'][$id] = isset($vars['classes'][$id]) ? implode(' ', $vars['classes'][$id]) : '';
+    $vars['row_classes'][$id] = isset($vars['classes'][$id]) ? implode(' ', $vars['classes'][$id]) : '';
   }
 }
 
diff --git a/theme/views-ui-display-tab-bucket.tpl.php b/theme/views-ui-display-tab-bucket.tpl.php
index 6d51a1d4f63b..5731328cdb2b 100644
--- a/theme/views-ui-display-tab-bucket.tpl.php
+++ b/theme/views-ui-display-tab-bucket.tpl.php
@@ -5,7 +5,7 @@
  * Template for each "box" on the display query edit screen.
  */
 ?>
-<div class="<?php print $classes; ?>" <?php print $attributes; ?>>
+<div <?php print $attributes; ?>>
   <?php print $item_help_icon; ?>
   <?php if(!empty($actions)) : ?>
     <?php print $actions; ?>
diff --git a/theme/views-ui-display-tab-setting.tpl.php b/theme/views-ui-display-tab-setting.tpl.php
index 3d13e12fd91c..be294b64016a 100644
--- a/theme/views-ui-display-tab-setting.tpl.php
+++ b/theme/views-ui-display-tab-setting.tpl.php
@@ -5,7 +5,7 @@
  * Template for each row inside the "boxes" on the display query edit screen.
  */
 ?>
-<div class="views-display-setting <?php print $classes; ?> <?php print $zebra; ?> clearfix" <?php print $attributes; ?>>
+<div class="views-display-setting <?php print $attributes['class']; ?> <?php print $zebra; ?> clearfix" <?php print $attributes; ?>>
   <?php if ($description): ?>
     <span class="label"><?php print $description; ?></span>
   <?php endif; ?>
diff --git a/theme/views-view-grid.tpl.php b/theme/views-view-grid.tpl.php
index cd8d39e3d709..603eed5e37d7 100644
--- a/theme/views-view-grid.tpl.php
+++ b/theme/views-view-grid.tpl.php
@@ -13,7 +13,7 @@
 <?php if (!empty($title)) : ?>
   <h3><?php print $title; ?></h3>
 <?php endif; ?>
-<table class="<?php print $class; ?>"<?php print $attributes; ?>>
+<table <?php print $attributes; ?>>
   <tbody>
     <?php foreach ($rows as $row_number => $columns): ?>
       <tr <?php if ($row_classes[$row_number]) { print 'class="' . $row_classes[$row_number] .'"';  } ?>>
diff --git a/theme/views-view-list.tpl.php b/theme/views-view-list.tpl.php
index 601279ae6984..2c4b9c5ecc6d 100644
--- a/theme/views-view-list.tpl.php
+++ b/theme/views-view-list.tpl.php
@@ -15,7 +15,7 @@
   <?php endif; ?>
   <?php print $list_type_prefix; ?>
     <?php foreach ($rows as $id => $row): ?>
-      <li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
+      <li <?php print $row_classes[$id]; ?>><?php print $row; ?></li>
     <?php endforeach; ?>
   <?php print $list_type_suffix; ?>
 <?php print $wrapper_suffix; ?>
diff --git a/theme/views-view-table.tpl.php b/theme/views-view-table.tpl.php
index a9abcd39a6d8..6dd130c16454 100644
--- a/theme/views-view-table.tpl.php
+++ b/theme/views-view-table.tpl.php
@@ -18,7 +18,7 @@
  * @ingroup views_templates
  */
 ?>
-<table <?php if ($classes) { print 'class="'. $classes . '" '; } ?><?php print $attributes; ?>>
+<table <?php print $attributes; ?>>
   <?php if (!empty($title)) : ?>
     <caption><?php print $title; ?></caption>
   <?php endif; ?>
diff --git a/theme/views-view-unformatted.tpl.php b/theme/views-view-unformatted.tpl.php
index 4f4558e09335..c5a34ae1bbce 100644
--- a/theme/views-view-unformatted.tpl.php
+++ b/theme/views-view-unformatted.tpl.php
@@ -11,7 +11,7 @@
   <h3><?php print $title; ?></h3>
 <?php endif; ?>
 <?php foreach ($rows as $id => $row): ?>
-  <div <?php if ($classes_array[$id]) { print 'class="' . $classes_array[$id] .'"';  } ?>>
+  <div <?php if ($row_classes[$id]) { print 'class="' . $row_classes[$id] .'"';  } ?>>
     <?php print $row; ?>
   </div>
 <?php endforeach; ?>
diff --git a/theme/views-view.tpl.php b/theme/views-view.tpl.php
index 579cf12a8d4c..130a24a8bf5e 100644
--- a/theme/views-view.tpl.php
+++ b/theme/views-view.tpl.php
@@ -5,14 +5,14 @@
  * Main view template.
  *
  * Variables available:
- * - $classes_array: An array of classes determined in
- *   template_preprocess_views_view(). Default classes are:
- *     .view
- *     .view-[css_name]
- *     .view-id-[view_name]
- *     .view-display-id-[display_name]
- *     .view-dom-id-[dom_id]
- * - $classes: A string version of $classes_array for use in the class attribute
+ * - $attributes: An instance of Attributes class that can be manipulated as an
+ *   array and printed as a string.
+ *   It includes the 'class' information, which includes:
+ *    .view
+ *    .view-[css_name]
+ *    .view-id-[view_name]
+ *    .view-display-id-[display_name]
+ *    .view-dom-id-[dom_id]
  * - $css_name: A css-safe version of the view name.
  * - $css_class: The user-specified classes names, if any
  * - $header: The view header
@@ -27,7 +27,7 @@
  * @ingroup views_templates
  */
 ?>
-<div class="<?php print $classes; ?>">
+<div <?php print $attributes; ?>">
   <?php print render($title_prefix); ?>
   <?php if ($title): ?>
     <?php print $title; ?>
diff --git a/views.module b/views.module
index 4d005ae8ce12..9e3f58115d30 100644
--- a/views.module
+++ b/views.module
@@ -594,12 +594,12 @@ function views_preprocess_html(&$variables) {
   // prefer a smaller region to be chosen. The region we prefer differs from
   // theme to theme and depends on the details of the theme's markup in
   // page.tpl.php, so we can only find it using JavaScript. We therefore remove
-  // the "contextual-links-region" class from the <body> tag here and add
+  // the "contextual-region" class from the <body> tag here and add
   // JavaScript that will insert it back in the correct place.
   if (!empty($variables['page']['#views_contextual_links_info'])) {
-    $key = array_search('contextual-links-region', $variables['classes_array']);
+    $key = array_search('contextual-region', $variables['attributes']['class']->value());
     if ($key !== FALSE) {
-      unset($variables['classes_array'][$key]);
+      unset($variables['attributes']['class'][$key]);
       // Add the JavaScript, with a group and weight such that it will run
       // before modules/contextual/contextual.js.
       drupal_add_js(drupal_get_path('module', 'views') . '/js/views-contextual.js', array('group' => JS_LIBRARY, 'weight' => -1));
diff --git a/views_ui.module b/views_ui.module
index 5c5e05c71742..620a6c79019a 100644
--- a/views_ui.module
+++ b/views_ui.module
@@ -372,7 +372,7 @@ function views_ui_preprocess_views_view(&$vars) {
           '#section' => $section,
           '#content' => is_array($vars[$section]) ? drupal_render($vars[$section]) : $vars[$section],
           '#theme_wrappers' => array('views_container'),
-          '#attributes' => array('class' => 'contextual-links-region'),
+          '#attributes' => array('class' => 'contextual-region'),
         );
         $vars[$section] = drupal_render($vars[$section]);
       }
@@ -434,7 +434,7 @@ function template_preprocess_views_ui_view_preview_section(&$vars) {
 
   if (isset($links)) {
     $build = array(
-      '#prefix' => '<div class="contextual-links-wrapper">',
+      '#prefix' => '<div class="contextual">',
       '#suffix' => '</div>',
       '#theme' => 'links__contextual',
       '#links' => $links,
-- 
GitLab