From c872abcac28ffce929af135129986fc1a2f5560a Mon Sep 17 00:00:00 2001 From: Konstantinos Platis <konstantinos.platis@cern.ch> Date: Wed, 16 Sep 2020 13:15:40 +0200 Subject: [PATCH] Modify display formats to keep css classes added manually in view config --- CHANGELOG.md | 1 + cern_display_formats.module | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdaf985..7a99793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.4.3] - Apply fix for Owl Carousel library loading in Horizontal Boxes view display format +- Modify display formats to keep css classes added manually in view config ## [1.4.2] - 25/05/2020 - Removed library declaration of JS file that does not exist diff --git a/cern_display_formats.module b/cern_display_formats.module index cf7be33..06978ea 100755 --- a/cern_display_formats.module +++ b/cern_display_formats.module @@ -41,11 +41,14 @@ function cern_display_formats_views_pre_render(ViewExecutable $view){ $admin_form = \Drupal::config('cern_display_formats.adminsettings'); // gets the admin form + // get css classes + $css_classes = $view->display_handler->getOption('css_class'); + $extra_class = ''; if ($view->display_handler->view->style_plugin->getPluginId() == "horizontal_boxes") { - $view->display_handler->setOption('css_class', 'horizontal-boxes'); $view->element['#attached']['library'][] = "cern_display_formats/horizontal-boxes-stylesheets"; //attaches the stylesheet + $extra_class = 'horizontal-boxes'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "collision") { - $view->display_handler->setOption('css_class', 'events-collision'); + $extra_class = 'events-collision'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "countdown") { $date_color = $admin_form->get('countdown_date_color'); $link_color = $admin_form->get('countdown_link_color'); @@ -56,9 +59,9 @@ function cern_display_formats_views_pre_render(ViewExecutable $view){ $view->element['#attached']['drupalSettings']['displayFormats']['countdown']['linkColor'] = $link_color; $view->element['#attached']['drupalSettings']['displayFormats']['countdown']['placeColor'] = $place_color; $view->element['#attached']['library'][] = 'cern_display_formats/countdown-stylesheets'; - $view->display_handler->setOption('css_class', 'events-countdown'); + $extra_class = 'events-countdown'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "teaser_list") { - $view->display_handler->setOption('css_class', 'teaser-list'); + $extra_class = 'teaser-list'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "featured_banner") { $link_color = $admin_form->get('featured_banner_link_color'); $subtext_color = $admin_form->get('featured_banner_subtext_color'); @@ -66,19 +69,23 @@ function cern_display_formats_views_pre_render(ViewExecutable $view){ $view->element['#attached']['drupalSettings']['displayFormats']['featured_banner']['linkColor'] = $link_color; $view->element['#attached']['drupalSettings']['displayFormats']['featured_banner']['subtextColor'] = $subtext_color; $view->element['#attached']['drupalSettings']['displayFormats']['featured_banner']['backgroundColor'] = $background_color; - $view->display_handler->setOption('css_class', 'featured-banner'); $view->element['#attached']['library'][] = "cern_display_formats/featured-banner-stylesheets"; //attaches the stylesheet + $extra_class = 'featured-banner'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "vertical_boxes") { - $view->display_handler->setOption('css_class', 'vertical-boxes'); + $extra_class = 'vertical-boxes'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "accordion") { - $view->display_handler->setOption('css_class', 'accordion-cern'); $view->element['#attached']['library'][] = 'cern_display_formats/accordion-stylesheets'; //attaches the stylesheet $title_color = $admin_form->get('accordion_title_color'); $view->element['#attached']['drupalSettings']['displayFormats']['accordion']['titleColor'] = $title_color; + $extra_class = 'accordion-cern'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "card_grid") { - $view->display_handler->setOption('css_class', 'card-grid'); + $extra_class = 'card-grid'; } elseif ($view->display_handler->view->style_plugin->getPluginId() == "event_grid") { - $view->display_handler->setOption('css_class', 'event-grid'); $view->element['#attached']['library'][] = "cern_display_formats/event-grid-stylesheets"; //attaches the stylesheet + $extra_class = 'event-grid'; } + + // glues together the rest of the css classes with the extra class + $css_classes = implode( ' ', array( $css_classes, $extra_class) ); + $view->display_handler->setOption('css_class', $css_classes); } -- GitLab