Commit 758cf21e authored by catch's avatar catch

Issue #2575735 by almaudoh: LibraryDiscoveryCollector::reset() does not...

Issue #2575735 by almaudoh: LibraryDiscoveryCollector::reset() does not properly reset its $cid, resulting in loading wrong library assets if the active theme changes
parent 4a11bb59
......@@ -1424,7 +1424,7 @@ services:
class: Drupal\Core\Asset\AssetDumper
library.discovery:
class: Drupal\Core\Asset\LibraryDiscovery
arguments: ['@library.discovery.collector', '@cache_tags.invalidator']
arguments: ['@library.discovery.collector']
library.discovery.collector:
class: Drupal\Core\Asset\LibraryDiscoveryCollector
arguments: ['@cache.discovery', '@lock', '@library.discovery.parser', '@theme.manager']
......
......@@ -8,7 +8,6 @@
namespace Drupal\Core\Asset;
use Drupal\Core\Cache\CacheCollectorInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
/**
* Discovers available asset libraries in Drupal.
......@@ -22,13 +21,6 @@ class LibraryDiscovery implements LibraryDiscoveryInterface {
*/
protected $collector;
/**
* The cache tag invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagInvalidator;
/**
* The final library definitions, statically cached.
*
......@@ -44,16 +36,9 @@ class LibraryDiscovery implements LibraryDiscoveryInterface {
*
* @param \Drupal\Core\Cache\CacheCollectorInterface $library_discovery_collector
* The library discovery cache collector.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tag_invalidator
* The cache tag invalidator.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function __construct(CacheCollectorInterface $library_discovery_collector, CacheTagsInvalidatorInterface $cache_tag_invalidator) {
public function __construct(CacheCollectorInterface $library_discovery_collector) {
$this->collector = $library_discovery_collector;
$this->cacheTagInvalidator = $cache_tag_invalidator;
}
/**
......@@ -84,7 +69,6 @@ public function getLibraryByName($extension, $name) {
* {@inheritdoc}
*/
public function clearCachedDefinitions() {
$this->cacheTagInvalidator->invalidateTags(['library_info']);
$this->libraryDefinitions = [];
$this->collector->clear();
}
......
......@@ -88,7 +88,6 @@ protected function resolveCacheMiss($key) {
return $this->storage[$key];
}
/**
* Returns the library definitions for a given extension.
*
......@@ -172,4 +171,13 @@ protected function applyLibrariesExtend($extension, $library_name, $library_defi
}
return $library_definition;
}
/**
* {@inheritdoc}
*/
public function reset() {
parent::reset();
$this->cid = NULL;
}
}
......@@ -36,11 +36,17 @@ protected function setUp() {
}
/**
* Ensures that the element info can be altered by themes.
* Tests that hook_library_info is invoked and the cache is cleared.
*/
public function testElementInfoByTheme() {
public function testHookLibraryInfoByTheme() {
// Activate test_theme and verify that the library 'kitten' is added using
// hook_library_info_alter().
$this->activateTheme('test_theme');
$this->assertTrue($this->libraryDiscovery->getLibraryByName('test_theme', 'kitten'));
// Now make classy the active theme and assert that library is not added.
$this->activateTheme('classy');
$this->assertFalse($this->libraryDiscovery->getLibraryByName('test_theme', 'kitten'));
}
/**
......
......@@ -29,8 +29,13 @@ function test_theme_element_info_alter(&$info) {
}
}
function test_theme_library_info_alter(&$libraries) {
$libraries['kitten']['js'][] = 'kittens.js';
/**
* Implements hook_library_info_alter().
*/
function test_theme_library_info_alter(&$libraries, $extension) {
if ($extension === 'test_theme') {
$libraries['kitten']['js']['kittens.js'] = [];
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment