diff --git a/cern_display_formats.module b/cern_display_formats.module index bd69563cbdc1d0d943a2d072e0c4c8284f5997cd..06102e960ee65aaef93891881c51412c9c2cc001 100755 --- a/cern_display_formats.module +++ b/cern_display_formats.module @@ -16,9 +16,6 @@ function cern_display_formats_theme($existing, $type, $theme, $path) { 'horizontal_boxes' => array( 'file' => 'display_formats.theme.inc', ), - 'accordion' => array( - 'file' => 'display_formats.theme.inc', - ), 'collision' => array( 'file' => 'display_formats.theme.inc', ), @@ -54,6 +51,7 @@ function cern_display_formats_views_post_render(ViewExecutable $view, &$output, $output['#attached']['library'][] = "cern_display_formats/featured-banner-stylesheets"; //attaches the stylesheet } elseif ($view->display_handler->view->style_plugin->getPluginId() == "vertical_boxes") { $view->display_handler->setOption('css_class', 'vertical-boxes'); + } elseif ($view->display_handler->view->style_plugin->getPluginId() == "accordion") { + $view->display_handler->setOption('css_class', 'accordion-cern'); } - } \ No newline at end of file diff --git a/display_formats.theme.inc b/display_formats.theme.inc index c5997d679bc9b26b5c8cc50cbdd8bdbc93953812..61ae8b7ada2a87f052bca8d68b425b2b5507990e 100755 --- a/display_formats.theme.inc +++ b/display_formats.theme.inc @@ -22,31 +22,9 @@ function template_preprocess_views_view_horizontal_boxes(&$variables) { $variables['rows'][$id]['attributes']->addClass($row_class); } } -// $variables['css_class'] = 'horizontal-boxes'; } -/** - * @file - * - */ -function template_preprocess_views_view_accordion(&$variables) { - $view = $variables['view']; - $rows = $variables['rows']; - $style = $view->style_plugin; - $options = $style->options; - - $variables['default_row_class'] = !empty($options['default_row_class']); - foreach ($rows as $id => $row) { - $variables['rows'][$id] = []; - $variables['rows'][$id]['content'] = $row; - $variables['rows'][$id]['attributes'] = new Attribute(); - if ($row_class = $view->style_plugin->getRowClass($id)) { - $variables['rows'][$id]['attributes']->addClass($row_class); - } - } -} - /** * Preprocess function of the Events Collision template. * diff --git a/src/Plugin/views/style/Accordion.php b/src/Plugin/views/style/Accordion.php index edebeeff7d83ecc4edb6ad9115c6ba4e520f47eb..a2ae76c9f486f72f27dada24d74a3090425e7a45 100644 --- a/src/Plugin/views/style/Accordion.php +++ b/src/Plugin/views/style/Accordion.php @@ -13,15 +13,12 @@ use Drupal\views\Plugin\views\style\DefaultStyle; * id = "accordion", * title = @Translation("Accordion"), * help = @Translation("Displays content in an accordion style"), - * theme = "views_view_accordion", + * theme = "views_view_unformatted", * display_types = {"normal"} * ) */ -class Accordion extends DefaultStyle -{ - /** - * {@inheritdoc} - */ +class Accordion extends DefaultStyle { + protected $usesRowPlugin = true; /** @@ -33,12 +30,34 @@ class Accordion extends DefaultStyle protected $usesoptions = true; - protected $renderFields = true; + /** + * Defines the initial options of the Horizontal Boxes. + * + * @return mixed + */ protected function defineOptions(){ $options = parent::defineOptions(); + $options['row_class'] = array('default'=> 'carousel-cern-item') ; return $options; } + /** + * Overrides the options form of Accordion + * + * @param $form + * @param FormStateInterface $form_state + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + parent::buildOptionsForm($form, $form_state); + + $form['row_class'] = array( + '#type' => 'textfield', + '#title' => t('Row Class'), + '#description' => t('For Accordion, make sure you have set carousel-cern-item as one of the row classes'), + '#default_value' => (!empty($this->options['row_class'])) ? $this->options['row_class'] : 'carousel-cern-item', + ); + } + } \ No newline at end of file diff --git a/src/Plugin/views/style/HorizontalBoxes.php b/src/Plugin/views/style/HorizontalBoxes.php index 5c87ca832f280aba2c279e382172980321b34c4e..afb842e603f768514a9f5b4f2a683a18a11bdb03 100755 --- a/src/Plugin/views/style/HorizontalBoxes.php +++ b/src/Plugin/views/style/HorizontalBoxes.php @@ -61,7 +61,7 @@ class HorizontalBoxes extends DefaultStyle '#description' => t('For Horizontal Boxes, make sure you have set horizontal-boxes-row as one of the row classes'), '#default_value' => (!empty($this->options['row_class'])) ? $this->options['row_class'] : 'horizontal-boxes-row', ); - } + } } \ No newline at end of file diff --git a/templates/views-view-accordion.html.twig b/templates/views-view-accordion.html.twig deleted file mode 100644 index 555c4e62d171c2438953f1627ffb00ba14fbfe7b..0000000000000000000000000000000000000000 --- a/templates/views-view-accordion.html.twig +++ /dev/null @@ -1,16 +0,0 @@ -<div class="panel-group accordion-cern"> - - {% for row in rows %} - {% set row_classes = [default_row_class ? 'views-row ',] %} - {% if loop.first != true and loop.index0 is divisible by(3) %} - </div> - {% endif %} - {% if loop.index0 is divisible by(3) %} - <div class="carousel-cern-item row"> - {% endif %} - <div{{ row.attributes.addClass(row_classes) }}>{{ row.content }}</div> - {% if loop.last == true %} - </div> - {% endif %} - {% endfor %} -</div> \ No newline at end of file