diff --git a/core/modules/system/src/Controller/AssetControllerBase.php b/core/modules/system/src/Controller/AssetControllerBase.php index 9544605..439da7c 100644 --- a/core/modules/system/src/Controller/AssetControllerBase.php +++ b/core/modules/system/src/Controller/AssetControllerBase.php @@ -167,8 +167,9 @@ public function deliver(Request $request, $file_name) { if ($request->query->has('already_loaded')) { $attached_assets->setAlreadyLoadedLibraries($request->query->get('already_loaded')); } - $group = $this->getGroup($attached_assets, $group_delta, $request); - $key = $this->generateHash($group); + $groups = $this->getGroups($attached_assets, $request); + $key = $this->generateHash($groups); + $group = $this->getGroup($groups, $group_delta); $hash = $file_parts[2]; // The hash from the library definitions in code may not match the hash from @@ -217,7 +218,7 @@ public function deliver(Request $request, $file_name) { $data = $this->optimizer->optimizeGroup($group); // Dump the optimized CSS for this group into an aggregate file. if ($match) { - $uri = $this->dumper->dump($data, $this->assetType, $uri); + $uri = $this->dumper->dumpToUri($data, $this->assetType, $uri); } $headers = [ 'Content-Type' => $this->contentType, @@ -233,17 +234,30 @@ public function deliver(Request $request, $file_name) { } /** - * Get assets of a certain type given attached assets. + * Get a group. * - * @param AttachedAssetsInterface $attached_assets - * An object implementing AttachedAssetsInterface + * @param array $groups + * An array of asset groups * @param int $group_delta * The group delta. - * @param Symfony\Component\HttpFoundation\Request - * The current request. * * @return [] * The correct asset group matching $group_delta. */ - abstract protected function getGroup(AttachedAssetsInterface $attached_assets, $group_delta, $request); + protected function getGroup($groups, $group_delta) { + if (isset($groups[$group_delta])) { + return $groups[$group_delta]; + } + throw new BadRequestHttpException('Invalid filename.'); + } + + /** + * Get grouped assets. + * + * @param Drupal\Core\Asset\AttachedAssetsInterface $attached_assets + * The attached assets. + * @param Symfony\Component\HttpFoundation\Request $request + * The current request. + */ + abstract protected function getGroups(AttachedAssetsInterface $attached_assets, Request $request); } diff --git a/core/modules/system/src/Controller/CssAssetController.php b/core/modules/system/src/Controller/CssAssetController.php index cab803c..32fdcf6 100644 --- a/core/modules/system/src/Controller/CssAssetController.php +++ b/core/modules/system/src/Controller/CssAssetController.php @@ -3,7 +3,7 @@ namespace Drupal\system\Controller; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Asset\AssetGroupSetHashTrait; @@ -41,15 +41,9 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - protected function getGroup(AttachedAssetsInterface $attached_assets, $group_delta, $request) { + protected function getGroups(AttachedAssetsInterface $attached_assets, Request $request) { $assets = $this->assetResolver->getCssAssets($attached_assets, FALSE); - - // Group the assets. - $groups = $this->grouper->group($assets); - if (!isset($groups[$group_delta])) { - throw new BadRequestHttpException('Invalid filename.'); - } - return $groups[$group_delta]; + return $this->grouper->group($assets); } } diff --git a/core/modules/system/src/Controller/JsAssetController.php b/core/modules/system/src/Controller/JsAssetController.php index 138f4a4..78ecfa3 100644 --- a/core/modules/system/src/Controller/JsAssetController.php +++ b/core/modules/system/src/Controller/JsAssetController.php @@ -3,7 +3,7 @@ namespace Drupal\system\Controller; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Asset\AssetGroupSetHashTrait; @@ -42,7 +42,7 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - protected function getGroup(AttachedAssetsInterface $attached_assets, $group_delta, $request) { + protected function getGroups(AttachedAssetsInterface $attached_assets, Request $request) { // The header and footer scripts are two distinct sets of asset groups. The // $group_key is not sufficient to find the group, we also need to locate it // within either the header or footer set. @@ -55,13 +55,7 @@ protected function getGroup(AttachedAssetsInterface $attached_assets, $group_del // While the asset resolver will find setting, these are never aggregated, // so filter them out. Settings are always in the header. unset($assets['drupalSettings']); - // Group the assets. - $groups = $this->grouper->group($assets); - if (!isset($groups[$group_delta])) { - throw new BadRequestHttpException('Invalid filename.'); - } - $group = $groups[$group_delta]; - return $group; + return $this->grouper->group($assets); } }