twig_extension example

/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests debug markup added to Twig template output. */
  public function testTwigDebugMarkup() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container->get('renderer');
    $extension = twig_extension();
    \Drupal::service('theme_installer')->install(['test_theme']);
    $this->config('system.theme')->set('default', 'test_theme')->save();
    $this->drupalCreateContentType(['type' => 'page']);
    // Enable debug, rebuild the service container, and clear all caches.     $parameters = $this->container->getParameter('twig.config');
    $parameters['debug'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();
    $this->resetAll();

    $cache = $this->container->get('theme.registry')->get();
    
$parameters['debug'] = FALSE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();

    $this->assertFalse($this->container->get('twig')->isDebug(), 'Twig debug disabled.');
  }

  /** * Ensures Twig template cache setting can be overridden. */
  public function testTwigCacheOverride() {
    $extension = twig_extension();
    $theme_installer = $this->container->get('theme_installer');
    $theme_installer->install(['test_theme']);
    $this->config('system.theme')->set('default', 'test_theme')->save();

    // The registry still works on theme globals, so set them here.     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->getActiveThemeByName('test_theme'));

    // Reset the theme registry, so that the new theme is used.     $this->container->set('theme.registry', NULL);

    // Load array of Twig templates.
Home | Imprint | This part of the site doesn't use cookies.