From ee29646356698f03a7dffb08cef086e4653ffded Mon Sep 17 00:00:00 2001 From: Shelane French <38005-shelane@users.noreply.drupalcode.org> Date: Thu, 30 May 2024 16:59:28 +0000 Subject: [PATCH] Issue #3024039 by shelane, gnikolovski, pixiekat, tguerineau: Provide class on the parent of rows --- src/Plugin/views/style/ViewsBootstrapGrid.php | 27 ++++++++++--------- views_bootstrap.theme.inc | 9 ++++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Plugin/views/style/ViewsBootstrapGrid.php b/src/Plugin/views/style/ViewsBootstrapGrid.php index 3a9fdfd..12f2631 100644 --- a/src/Plugin/views/style/ViewsBootstrapGrid.php +++ b/src/Plugin/views/style/ViewsBootstrapGrid.php @@ -41,22 +41,11 @@ class ViewsBootstrapGrid extends StylePluginBase { protected function defineOptions() { $options = parent::defineOptions(); + $options['grid_class'] = ['default' => '']; foreach (ViewsBootstrap::getBreakpoints() as $breakpoint) { $breakpoint_option = "col_$breakpoint"; $options[$breakpoint_option] = ['default' => 'none']; } - $options['col_class_custom'] = ['default' => '']; - $options['col_class_default'] = ['default' => TRUE]; - $options['row_class_custom'] = ['default' => '']; - $options['row_class_default'] = ['default' => TRUE]; - $options['default'] = ['default' => '']; - $options['info'] = ['default' => []]; - $options['override'] = ['default' => TRUE]; - $options['sticky'] = ['default' => FALSE]; - $options['order'] = ['default' => 'asc']; - $options['caption'] = ['default' => '']; - $options['summary'] = ['default' => '']; - $options['description'] = ['default' => '']; return $options; } @@ -66,13 +55,25 @@ class ViewsBootstrapGrid extends StylePluginBase { public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); + $form['grid_class'] = [ + '#title' => $this->t('Grid row custom class'), + '#description' => $this->t('Additional classes to provide on the grid row. Separated by a space.'), + '#type' => 'textfield', + '#size' => '30', + '#default_value' => $this->options['grid_class'], + '#weight' => 1, + ]; + + $form['row_class']['#title'] = $this->t('Custom column class'); + $form['row_class']['#weight'] = 2; + foreach (ViewsBootstrap::getBreakpoints() as $breakpoint) { $breakpoint_option = "col_$breakpoint"; $prefix = 'col' . ($breakpoint != 'xs' ? '-' . $breakpoint : ''); $form[$breakpoint_option] = [ '#type' => 'select', '#title' => $this->t("Column width of items at @breakpoint breakpoint", ['@breakpoint' => $breakpoint]), - '#default_value' => isset($this->options[$breakpoint_option]) ? $this->options[$breakpoint_option] : NULL, + '#default_value' => $this->options[$breakpoint_option] ?? NULL, '#description' => $this->t("Set the number of columns each item should take up at the @breakpoint breakpoint and higher.", ['@breakpoint' => $breakpoint]), '#options' => [ 'none' => $this->t('None (or inherit from previous)'), diff --git a/views_bootstrap.theme.inc b/views_bootstrap.theme.inc index 8ff73bd..5fdbd1c 100644 --- a/views_bootstrap.theme.inc +++ b/views_bootstrap.theme.inc @@ -5,6 +5,7 @@ * Preprocessors and helper functions to make theming easier. */ +use Drupal\Component\Utility\Html; use Drupal\views_bootstrap\ViewsBootstrap; use Drupal\Core\Template\Attribute; @@ -132,9 +133,15 @@ function template_preprocess_views_bootstrap_carousel(array &$vars) { function template_preprocess_views_bootstrap_grid(array &$vars) { $view = $vars['view']; $vars['id'] = ViewsBootstrap::getUniqueId($view); - $vars['attributes']['class'][] = 'grid'; + $vars['attributes'] = new Attribute(['class' => 'grid']); $options = $view->style_plugin->options; + if ($options['grid_class']) { + $grid_class = explode(' ', $options['grid_class']); + $grid_classes = array_map([Html::class, 'cleanCssIdentifier'], array_filter($grid_class)); + $vars['attributes']->addClass($grid_classes); + } + $vars['row_attributes'] = new Attribute(); foreach (ViewsBootstrap::getBreakpoints() as $breakpoint) { if ($options["col_$breakpoint"] == 'none') { -- GitLab