diff --git a/core/lib/Drupal/Core/Asset/AssetResolver.php b/core/lib/Drupal/Core/Asset/AssetResolver.php index 3ffd7a9..003d88c 100644 --- a/core/lib/Drupal/Core/Asset/AssetResolver.php +++ b/core/lib/Drupal/Core/Asset/AssetResolver.php @@ -285,7 +285,7 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize) { $js_assets_header = []; $js_assets_footer = []; foreach ($javascript as $key => $item) { - if ($item['scope'] == 'header' && $item['type'] !== 'setting') { + if ($item['scope'] == 'header') { $js_assets_header[$key] = $item; } elseif ($item['scope'] == 'footer') { @@ -295,9 +295,7 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize) { if ($optimize) { $collection_optimizer = \Drupal::service('asset.js.collection_optimizer'); - if ($js_assets_header) { - $js_assets_header = $collection_optimizer->optimize($js_assets_header); - } + $js_assets_header = $collection_optimizer->optimize($js_assets_header); $js_assets_footer = $collection_optimizer->optimize($js_assets_footer); } diff --git a/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php b/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php index 710e3c0..2b38d6d 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php @@ -45,6 +45,9 @@ public function group(array $js_assets) { // Do not group external items. $group_keys = FALSE; break; + default: + $e = new \Exception(); + trigger_error($e->getTraceAsString()); } // If the group keys don't match the most recent group we're working with, diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php index d636a4d..4aa4383 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php @@ -53,6 +53,7 @@ public function optimize(array $js_assets) { $key = $this->generateHash($js_groups); $js_assets = array(); + $libraries = []; foreach ($js_groups as $order => $js_group) { // We have to return a single asset, not a group of assets. It is now up // to one of the pieces of code in the switch statement below to set the @@ -85,6 +86,9 @@ public function optimize(array $js_assets) { $uri = $js_group['items'][0]['data']; $js_assets[$order]['data'] = $uri; break; + case 'setting': + $js_assets[$order]['data'] = $js_group['data']; + break; } } if ($libraries) { diff --git a/core/modules/system/src/Controller/CssAssetController.php b/core/modules/system/src/Controller/CssAssetController.php index 8796880..8f1b0b5 100644 --- a/core/modules/system/src/Controller/CssAssetController.php +++ b/core/modules/system/src/Controller/CssAssetController.php @@ -46,7 +46,7 @@ protected function getKeyAndGroup(AttachedAssetsInterface $attached_assets, $gro // Group the assets. $groups = $this->grouper->group($assets); - if (!isset($groups[$group_delta]['preprocess'])) { + if (!isset($groups[$group_delta])) { throw new BadRequestHttpException('Invalid filename.'); } $group = $groups[$group_delta]; diff --git a/core/modules/system/src/Controller/JsAssetController.php b/core/modules/system/src/Controller/JsAssetController.php index de6a142..4fdf401 100644 --- a/core/modules/system/src/Controller/JsAssetController.php +++ b/core/modules/system/src/Controller/JsAssetController.php @@ -54,14 +54,10 @@ protected function getKeyAndGroup(AttachedAssetsInterface $attached_assets, $gro $assets = $scope == 'header' ? $js_assets_header : $js_assets_footer; // While the asset resolver will find setting, these are never aggregated, // so filter them out. Settings are always in the header. - if ($scope == 'header') { - $assets = array_filter($assets, function($item) { - return $item['type'] !== 'setting'; - }); - } + unset($assets['drupalSettings']); // Group the assets. $groups = $this->grouper->group($assets); - if (!isset($groups[$group_delta]['preprocess'])) { + if (!isset($groups[$group_delta])) { throw new BadRequestHttpException('Invalid filename.'); } $group = $groups[$group_delta];