From 1453f80e76659b95de89871e3f017a9200fb1832 Mon Sep 17 00:00:00 2001
From: Konstantinos Platis <konstantinos.platis@cern.ch>
Date: Mon, 1 Jul 2019 18:09:23 +0200
Subject: [PATCH] Fixed issue of styles rendering after 1 sec (changed
 post_render to pre_render)

---
 cern_display_formats.module | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/cern_display_formats.module b/cern_display_formats.module
index 2597de0..a724ab6 100755
--- a/cern_display_formats.module
+++ b/cern_display_formats.module
@@ -32,12 +32,12 @@ function cern_display_formats_theme($existing, $type, $theme, $path) {
     );
 }
 
-
 /**
- * Implements hook_views_post_render().
+ * Sets css classes and theming libraries before rendering the view
+ *
+ * @param ViewExecutable $view
  */
-function cern_display_formats_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
-	//sets css classes to the view based on selected format
+function cern_display_formats_views_pre_render(ViewExecutable $view){
 	if ($view->display_handler->view->style_plugin->getPluginId() == "horizontal_boxes") {
 		$view->display_handler->setOption('css_class', 'horizontal-boxes');
 	} elseif ($view->display_handler->view->style_plugin->getPluginId() == "collision") {
@@ -49,22 +49,22 @@ function cern_display_formats_views_post_render(ViewExecutable $view, &$output,
 		// injects the settings of teaser_list in the JS file
 		$title_color = $view->style_plugin->options['title_color'];
 		$title_color_card = $view->style_plugin->options['title_color_card'];
-		$output['#attached']['drupalSettings']['displayFormats']['teaser_list']['titleColor'] = $title_color;
-		$output['#attached']['drupalSettings']['displayFormats']['teaser_list']['titleColorCard'] = $title_color_card;
+		$view->element['#attached']['drupalSettings']['displayFormats']['teaser_list']['titleColor'] = $title_color;
+		$view->element['#attached']['drupalSettings']['displayFormats']['teaser_list']['titleColorCard'] = $title_color_card;
 	} elseif ($view->display_handler->view->style_plugin->getPluginId() == "featured_banner") {
 		$view->display_handler->setOption('css_class', 'featured-banner');
-		$output['#attached']['library'][] = "cern_display_formats/featured-banner-stylesheets";	//attaches the stylesheet
+		$view->element['#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');
-		$output['#attached']['library'][] = 'cern_display_formats/accordion-stylesheets'; //attaches the stylesheet
+		$view->element['#attached']['library'][] = 'cern_display_formats/accordion-stylesheets'; //attaches the stylesheet
 		$title_color = $view->style_plugin->options['title_color'];
-		$output['#attached']['drupalSettings']['displayFormats']['accordion']['titleColor'] = $title_color;
+		$view->element['#attached']['drupalSettings']['displayFormats']['accordion']['titleColor'] = $title_color;
 	} elseif ($view->display_handler->view->style_plugin->getPluginId() == "card_grid") {
 		$view->display_handler->setOption('css_class', 'cern-view-display-page cern-view-display-resources');
 	} elseif ($view->display_handler->view->style_plugin->getPluginId() == "event_grid") {
 		$view->display_handler->setOption('css_class', 'event-grid');
-		$output['#attached']['library'][] = "cern_display_formats/event-grid-stylesheets";	//attaches the stylesheet
+		$view->element['#attached']['library'][] = "cern_display_formats/event-grid-stylesheets";	//attaches the stylesheet
 	}
 }
\ No newline at end of file
-- 
GitLab