diff --git a/core/modules/views/src/Element/View.php b/core/modules/views/src/Element/View.php index 62fc24cab13ac6ff6868dac5677e18aed306c9c9..e12037ed2a4995b8cecbad7a25c2952f981b553a 100644 --- a/core/modules/views/src/Element/View.php +++ b/core/modules/views/src/Element/View.php @@ -51,6 +51,7 @@ public static function preRenderViewElement($element) { $view = $element['#view']; } + $element += $view->element; $view->element = &$element; // Mark the element as being prerendered, so other code like // \Drupal\views\ViewExecutable::setCurrentPage knows that its no longer diff --git a/core/modules/views/src/Tests/Plugin/StyleGridTest.php b/core/modules/views/src/Tests/Plugin/StyleGridTest.php index d5d7e60376cd8abb2141fc995ce5c45b48c7dd7b..ea212ddde7bd7091a5af1d122baf886b4eeac196 100644 --- a/core/modules/views/src/Tests/Plugin/StyleGridTest.php +++ b/core/modules/views/src/Tests/Plugin/StyleGridTest.php @@ -51,6 +51,10 @@ public function testGrid() { $this->assertGrid($view, $alignment, 2); $this->assertGrid($view, $alignment, 1); } + + // Ensure styles are properly added for grid views. + $this->drupalGet('test-grid'); + $this->assertRaw('views/css/views.module.css'); } /** diff --git a/core/modules/views/src/Tests/ViewAjaxTest.php b/core/modules/views/src/Tests/ViewAjaxTest.php index 35b5518b69f0872c4a184132eebfb38afc6d5f89..541b6ef4a99218229e68308cd79c87c41ae5e1c3 100644 --- a/core/modules/views/src/Tests/ViewAjaxTest.php +++ b/core/modules/views/src/Tests/ViewAjaxTest.php @@ -55,13 +55,12 @@ public function testAjaxView() { $data = Json::decode($response); $this->assertTrue(isset($data[0]['settings']['views']['ajaxViews'])); - $this->assertEqual($data[1]['command'], 'add_css'); // Ensure that the view insert command is part of the result. - $this->assertEqual($data[2]['command'], 'insert'); - $this->assertTrue(strpos($data[2]['selector'], '.js-view-dom-id-') === 0); + $this->assertEqual($data[1]['command'], 'insert'); + $this->assertTrue(strpos($data[1]['selector'], '.js-view-dom-id-') === 0); - $this->setRawContent($data[2]['data']); + $this->setRawContent($data[1]['data']); $result = $this->xpath('//div[contains(@class, "views-row")]'); $this->assertEqual(count($result), 2, 'Ensure that two items are rendered in the HTML.'); } diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 3638c9cd45f091e206b5de4160cb0334f9ec518e..0fe630c711040a176675612b394dcc3aee000fe5 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -403,7 +403,7 @@ class ViewExecutable implements \Serializable { */ public $element = [ '#attached' => [ - 'library' => [], + 'library' => ['views/views.module'], 'drupalSettings' => [], ], '#cache' => [], @@ -456,9 +456,6 @@ public function __construct(ViewEntityInterface $storage, AccountInterface $user $this->user = $user; $this->viewsData = $views_data; $this->routeProvider = $route_provider; - - // Add the default css for a view. - $this->element['#attached']['library'][] = 'views/views.module'; } /**