class DevelopmentSettingsPass

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/DependencyInjection/Compiler/DevelopmentSettingsPass.php \Drupal\Core\DependencyInjection\Compiler\DevelopmentSettingsPass

Defines a compiler pass to register development settings.

Hierarchy

  • class \Drupal\Core\DependencyInjection\Compiler\DevelopmentSettingsPass extends \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

Expanded class hierarchy of DevelopmentSettingsPass

1 file declares its use of DevelopmentSettingsPass
CoreServiceProvider.php in core/lib/Drupal/Core/CoreServiceProvider.php

File

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

Namespace

Drupal\Core\DependencyInjection\Compiler
View source
class DevelopmentSettingsPass implements CompilerPassInterface {
  
  /**
   * {@inheritdoc}
   */
  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',
          ]);
        }
      }
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary
DevelopmentSettingsPass::process public function

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