diff --git a/CHANGELOG.md b/CHANGELOG.md index cdaf985e8695c97ae540a7b2e8b1b82510a81511..7a99793a38bb8b3d58222f8d1c214b09fd3c59c9 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 cf7be33f948aed3a276e3065175e685bb4999f39..06978ea52b9083cf17577c515ed2bc72c4eedd7c 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); }