Skip to content

Commit ee3c7b8

Browse files
author
catch
committed
Revert "Issue #3464388 by vidorado, mogtofu33, smustgrave, wim leers: SDC *.component.yml metadata is cached aggressively, gets in the way of component development"
This reverts commit f3b0c8db916677f64e57d046a809634540e1c51a.
1 parent ed9223a commit ee3c7b8

File tree

3 files changed

+0
-62
lines changed

3 files changed

+0
-62
lines changed

core.services.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,6 @@ services:
18871887
- '@file_system'
18881888
- '@Drupal\Core\Theme\Component\SchemaCompatibilityChecker'
18891889
- '@Drupal\Core\Theme\Component\ComponentValidator'
1890-
- '@keyvalue'
18911890
- '%app.root%'
18921891
Drupal\Core\Theme\ComponentPluginManager: '@plugin.manager.sdc'
18931892
Drupal\Core\Template\Loader\ComponentLoader:

lib/Drupal/Core/Theme/ComponentPluginManager.php

-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Drupal\Core\Extension\ModuleHandlerInterface;
1313
use Drupal\Core\Extension\ThemeHandlerInterface;
1414
use Drupal\Core\File\FileSystemInterface;
15-
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
1615
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
1716
use Drupal\Core\Plugin\DefaultPluginManager;
1817
use Drupal\Core\Plugin\Factory\ContainerFactory;
@@ -63,8 +62,6 @@ class ComponentPluginManager extends DefaultPluginManager implements Categorizin
6362
* The compatibility checker.
6463
* @param \Drupal\Core\Theme\Component\ComponentValidator $componentValidator
6564
* The component validator.
66-
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $keyValueFactory
67-
* The key value factory.
6865
* @param string $appRoot
6966
* The application root.
7067
*/
@@ -78,7 +75,6 @@ public function __construct(
7875
protected FileSystemInterface $fileSystem,
7976
protected SchemaCompatibilityChecker $compatibilityChecker,
8077
protected ComponentValidator $componentValidator,
81-
protected KeyValueFactoryInterface $keyValueFactory,
8278
protected string $appRoot,
8379
) {
8480
// We are skipping the call to the parent constructor to avoid initializing
@@ -128,19 +124,6 @@ public function createInstance($plugin_id, array $configuration = []): Component
128124
}
129125
}
130126

131-
/**
132-
* {@inheritdoc}
133-
*/
134-
public function getDefinitions(): array {
135-
$development_settings = $this->keyValueFactory->get('development_settings');
136-
$twig_debug = $development_settings->get('twig_debug', FALSE);
137-
$twig_cache_disable = $development_settings->get('twig_cache_disable', FALSE);
138-
if ($twig_debug || $twig_cache_disable) {
139-
return $this->findDefinitions();
140-
}
141-
return parent::getDefinitions();
142-
}
143-
144127
/**
145128
* Gets a component for rendering.
146129
*

tests/Drupal/KernelTests/Components/ComponentPluginManagerTest.php

-44
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Drupal\KernelTests\Components;
66

77
use Drupal\Core\Render\Component\Exception\ComponentNotFoundException;
8-
use Drupal\Core\Cache\CacheBackendInterface;
98

109
/**
1110
* Tests the component plugin manager.
@@ -50,47 +49,4 @@ public function testMismatchingFolderName(): void {
5049
$this->manager->find('sdc_theme_test:mismatching-folder-name');
5150
}
5251

53-
/**
54-
* Test component definitions caching depending on twig debug/cache settings.
55-
*
56-
* @param bool $twigDebug
57-
* Whether twig debug is enabled.
58-
* @param bool $cacheEnabled
59-
* Whether cache is enabled.
60-
* @param bool $expectCacheGet
61-
* Whether we expect the cache to be called.
62-
*
63-
* @dataProvider providerTestComponentCachingDependingOnDevelopmentSettings
64-
*/
65-
public function testComponentCachingDependingOnDevelopmentSettings(bool $twigDebug, bool $cacheEnabled, bool $expectCacheGet): void {
66-
// Set the development settings.
67-
$developmentSettings = $this->keyValue->get('development_settings');
68-
$developmentSettings->set('twig_debug', $twigDebug);
69-
$developmentSettings->set('twig_cache_disable', !$cacheEnabled);
70-
71-
// Set the cache backend as a spy mock.
72-
$cacheBackend = $this->createMock(CacheBackendInterface::class);
73-
$cacheBackend->expects($expectCacheGet ? $this->once() : $this->never())
74-
->method('get')
75-
->with('cache_key');
76-
$this->manager->setCacheBackend($cacheBackend, 'cache_key');
77-
78-
// Make two calls to getDefinitions() to ensure the
79-
// cache is/isn't called if it should/shouldn't be.
80-
$this->manager->getDefinitions();
81-
$this->manager->getDefinitions();
82-
}
83-
84-
/**
85-
* Data provider for testComponentCachingDependingOnDevelopmentSettings().
86-
*/
87-
public static function providerTestComponentCachingDependingOnDevelopmentSettings(): array {
88-
return [
89-
'Debug enabled, cache enabled' => [TRUE, TRUE, FALSE],
90-
'Debug enabled, cache disabled' => [TRUE, FALSE, FALSE],
91-
'Debug disabled, cache enabled' => [FALSE, TRUE, TRUE],
92-
'Debug disabled, cache disabled' => [FALSE, FALSE, FALSE],
93-
];
94-
}
95-
9652
}

0 commit comments

Comments
 (0)