function DevelopmentSettingsPass::process

Same name in other branches
  1. 11.x core/lib/Drupal/Core/DependencyInjection/Compiler/DevelopmentSettingsPass.php \Drupal\Core\DependencyInjection\Compiler\DevelopmentSettingsPass::process()

File

core/lib/Drupal/Core/DependencyInjection/Compiler/DevelopmentSettingsPass.php, line 17

Class

DevelopmentSettingsPass
Defines a compiler pass to register development settings.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

public function process(ContainerBuilder $container) : void {
    
    /** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $development_settings */
    $development_settings = $container->get('keyvalue')
        ->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) {
        $twig_config = $container->getParameter('twig.config');
        $twig_config['debug'] = $twig_debug;
        $twig_config['cache'] = !$twig_cache_disable;
        $container->setParameter('twig.config', $twig_config);
    }
    if ($development_settings->get('disable_rendered_output_cache_bins', FALSE)) {
        $cache_bins = [
            'page',
            'dynamic_page_cache',
            'render',
        ];
        if (!$container->hasDefinition('cache.backend.null')) {
            $container->register('cache.backend.null', NullBackendFactory::class);
        }
        foreach ($cache_bins as $cache_bin) {
            if ($container->has("cache.{$cache_bin}")) {
                $container->getDefinition("cache.{$cache_bin}")
                    ->clearTag('cache.bin')
                    ->addTag('cache.bin', [
                    'default_backend' => 'cache.backend.null',
                ]);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.