Skip to content
Snippets Groups Projects
Commit f3b0c8db authored by catch's avatar catch
Browse files

Issue #3464388 by vidorado, mogtofu33, smustgrave, wim leers: SDC...

Issue #3464388 by vidorado, mogtofu33, smustgrave, wim leers: SDC *.component.yml metadata is cached aggressively, gets in the way of component development
parent b68174aa
No related branches found
No related tags found
4 merge requests!5423Draft: Resolve #3329907 "Test2",!3478Issue #3337882: Deleted menus are not removed from content type config,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #439704 passed with warnings
Pipeline: drupal

#439713

    Pipeline: drupal

    #439710

      Pipeline: drupal

      #439707

        ...@@ -1887,6 +1887,7 @@ services: ...@@ -1887,6 +1887,7 @@ services:
        - '@file_system' - '@file_system'
        - '@Drupal\Core\Theme\Component\SchemaCompatibilityChecker' - '@Drupal\Core\Theme\Component\SchemaCompatibilityChecker'
        - '@Drupal\Core\Theme\Component\ComponentValidator' - '@Drupal\Core\Theme\Component\ComponentValidator'
        - '@keyvalue'
        - '%app.root%' - '%app.root%'
        Drupal\Core\Theme\ComponentPluginManager: '@plugin.manager.sdc' Drupal\Core\Theme\ComponentPluginManager: '@plugin.manager.sdc'
        Drupal\Core\Template\Loader\ComponentLoader: Drupal\Core\Template\Loader\ComponentLoader:
        ......
        ...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
        use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
        use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface;
        use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
        use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
        use Drupal\Core\Plugin\CategorizingPluginManagerTrait; use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
        use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\DefaultPluginManager;
        use Drupal\Core\Plugin\Factory\ContainerFactory; use Drupal\Core\Plugin\Factory\ContainerFactory;
        ...@@ -62,6 +63,8 @@ class ComponentPluginManager extends DefaultPluginManager implements Categorizin ...@@ -62,6 +63,8 @@ class ComponentPluginManager extends DefaultPluginManager implements Categorizin
        * The compatibility checker. * The compatibility checker.
        * @param \Drupal\Core\Theme\Component\ComponentValidator $componentValidator * @param \Drupal\Core\Theme\Component\ComponentValidator $componentValidator
        * The component validator. * The component validator.
        * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $keyValueFactory
        * The key value factory.
        * @param string $appRoot * @param string $appRoot
        * The application root. * The application root.
        */ */
        ...@@ -75,6 +78,7 @@ public function __construct( ...@@ -75,6 +78,7 @@ public function __construct(
        protected FileSystemInterface $fileSystem, protected FileSystemInterface $fileSystem,
        protected SchemaCompatibilityChecker $compatibilityChecker, protected SchemaCompatibilityChecker $compatibilityChecker,
        protected ComponentValidator $componentValidator, protected ComponentValidator $componentValidator,
        protected KeyValueFactoryInterface $keyValueFactory,
        protected string $appRoot, protected string $appRoot,
        ) { ) {
        // We are skipping the call to the parent constructor to avoid initializing // We are skipping the call to the parent constructor to avoid initializing
        ...@@ -124,6 +128,19 @@ public function createInstance($plugin_id, array $configuration = []): Component ...@@ -124,6 +128,19 @@ public function createInstance($plugin_id, array $configuration = []): Component
        } }
        } }
        /**
        * {@inheritdoc}
        */
        public function getDefinitions(): array {
        $development_settings = $this->keyValueFactory->get('development_settings');
        $twig_debug = $development_settings->get('twig_debug', FALSE);
        $twig_cache_disable = $development_settings->get('twig_cache_disable', FALSE);
        if ($twig_debug || $twig_cache_disable) {
        return $this->findDefinitions();
        }
        return parent::getDefinitions();
        }
        /** /**
        * Gets a component for rendering. * Gets a component for rendering.
        * *
        ......
        ...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
        namespace Drupal\KernelTests\Components; namespace Drupal\KernelTests\Components;
        use Drupal\Core\Render\Component\Exception\ComponentNotFoundException; use Drupal\Core\Render\Component\Exception\ComponentNotFoundException;
        use Drupal\Core\Cache\CacheBackendInterface;
        /** /**
        * Tests the component plugin manager. * Tests the component plugin manager.
        ...@@ -49,4 +50,47 @@ public function testMismatchingFolderName(): void { ...@@ -49,4 +50,47 @@ public function testMismatchingFolderName(): void {
        $this->manager->find('sdc_theme_test:mismatching-folder-name'); $this->manager->find('sdc_theme_test:mismatching-folder-name');
        } }
        /**
        * Test component definitions caching depending on twig debug/cache settings.
        *
        * @param bool $twigDebug
        * Whether twig debug is enabled.
        * @param bool $cacheEnabled
        * Whether cache is enabled.
        * @param bool $expectCacheGet
        * Whether we expect the cache to be called.
        *
        * @dataProvider providerTestComponentCachingDependingOnDevelopmentSettings
        */
        public function testComponentCachingDependingOnDevelopmentSettings(bool $twigDebug, bool $cacheEnabled, bool $expectCacheGet): void {
        // Set the development settings.
        $developmentSettings = $this->keyValue->get('development_settings');
        $developmentSettings->set('twig_debug', $twigDebug);
        $developmentSettings->set('twig_cache_disable', !$cacheEnabled);
        // Set the cache backend as a spy mock.
        $cacheBackend = $this->createMock(CacheBackendInterface::class);
        $cacheBackend->expects($expectCacheGet ? $this->once() : $this->never())
        ->method('get')
        ->with('cache_key');
        $this->manager->setCacheBackend($cacheBackend, 'cache_key');
        // Make two calls to getDefinitions() to ensure the
        // cache is/isn't called if it should/shouldn't be.
        $this->manager->getDefinitions();
        $this->manager->getDefinitions();
        }
        /**
        * Data provider for testComponentCachingDependingOnDevelopmentSettings().
        */
        public static function providerTestComponentCachingDependingOnDevelopmentSettings(): array {
        return [
        'Debug enabled, cache enabled' => [TRUE, TRUE, FALSE],
        'Debug enabled, cache disabled' => [TRUE, FALSE, FALSE],
        'Debug disabled, cache enabled' => [FALSE, TRUE, TRUE],
        'Debug disabled, cache disabled' => [FALSE, FALSE, FALSE],
        ];
        }
        } }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment