Mercurial > hg > cmmr2012-drupal-site
diff core/modules/views/views.theme.inc @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
line wrap: on
line diff
--- a/core/modules/views/views.theme.inc Thu Feb 28 11:14:44 2019 +0000 +++ b/core/modules/views/views.theme.inc Thu Feb 28 13:11:55 2019 +0000 @@ -34,8 +34,17 @@ $css_class = $view->display_handler->getOption('css_class'); if (!empty($css_class)) { - $variables['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class); - $variables['attributes']['class'][] = $variables['css_class']; + // Views uses its own sanitization method. This is preserved to keep + // backwards compatibility. + // @todo https://www.drupal.org/project/drupal/issues/2977950 Decide what to + // do with the backwards compatibility layer. + $bc_classes = explode(' ', preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class)); + // Sanitize the classes using the classes using the proper API. + $sanitized_classes = array_map('\Drupal\Component\Utility\Html::cleanCssIdentifier', explode(' ', $css_class)); + $view_classes = array_unique(array_merge($bc_classes, $sanitized_classes)); + // Merge the view display classes into any existing classes if they exist. + $variables['attributes']['class'] = !empty($variables['attributes']['class']) ? array_merge($variables['attributes']['class'], $view_classes) : $view_classes; + $variables['css_class'] = implode(' ', $view_classes); } // contextual_preprocess() only works on render elements, and since this theme @@ -575,12 +584,12 @@ if (!empty($column_reference['content']) && !empty($options['info'][$column]['separator'])) { $column_reference['content'][] = [ 'separator' => ['#markup' => $options['info'][$column]['separator']], - 'field_output' => ['#markup' => $field_output] + 'field_output' => ['#markup' => $field_output], ]; } else { $column_reference['content'][] = [ - 'field_output' => ['#markup' => $field_output] + 'field_output' => ['#markup' => $field_output], ]; } } @@ -802,7 +811,7 @@ * - view: A View object. */ function template_preprocess_views_view_list(&$variables) { - $handler = $variables['view']->style_plugin; + $handler = $variables['view']->style_plugin; // Fetch classes from handler options. if ($handler->options['class']) { @@ -835,7 +844,7 @@ * - rows: The raw row data. */ function template_preprocess_views_view_rss(&$variables) { - $view = $variables['view']; + $view = $variables['view']; $items = $variables['rows']; $style = $view->style_plugin; @@ -936,7 +945,7 @@ * - rows: The raw row data. */ function template_preprocess_views_view_opml(&$variables) { - $view = $variables['view']; + $view = $variables['view']; $items = $variables['rows']; $config = \Drupal::config('system.site');