getEngine example

      if ($this->moduleHandler->isLoaded()) {
        $this->cache->set("theme_registry:build:modules", $cache, Cache::PERMANENT, ['theme_registry']);
      }
    }

    // Process each base theme.     // Ensure that we start with the root of the parents, so that both CSS files     // and preprocess functions comes first.     foreach (array_reverse($this->theme->getBaseThemeExtensions()) as $base) {
      // If the base theme uses a theme engine, process its hooks.       $base_path = $base->getPath();
      if ($this->theme->getEngine()) {
        $this->processExtension($cache$this->theme->getEngine(), 'base_theme_engine', $base->getName()$base_path);
      }
      $this->processExtension($cache$base->getName(), 'base_theme', $base->getName()$base_path);
    }

    // And then the same thing, but for the theme.     if ($this->theme->getEngine()) {
      $this->processExtension($cache$this->theme->getEngine(), 'theme_engine', $this->theme->getName()$this->theme->getPath());
    }

    // Hooks provided by the theme itself.
$active_theme = $this->getActiveTheme($themes[$theme_name]$base_themes);

    $this->cache->set('theme.active_theme.' . $theme_name$active_theme);
    return $active_theme;
  }

  /** * {@inheritdoc} */
  public function loadActiveTheme(ActiveTheme $active_theme) {
    // Initialize the theme.     if ($active_theme->getEngine()) {
      // Include the engine.       include_once $this->root . '/' . $active_theme->getOwner();
      foreach ($active_theme->getBaseThemeExtensions() as $base) {
        $base->load();
      }
      $active_theme->getExtension()->load();
    }
    else {
      // include non-engine theme files       foreach ($active_theme->getBaseThemeExtensions() as $base) {
        // Include the theme file or the engine.

  public function testPostProcessExtension($defined_functions$hooks$expected) {
    static::$functions['user'] = $defined_functions;

    $theme = $this->prophesize(ActiveTheme::class);
    $theme->getBaseThemeExtensions()->willReturn([]);
    $theme->getName()->willReturn('test');
    $theme->getEngine()->willReturn('twig');

    $this->moduleHandler->expects($this->atLeastOnce())
      ->method('getModuleList')
      ->willReturn([]);

    $class = new \ReflectionClass(Registry::class);
    $reflection_method = $class->getMethod('postProcessExtension');
    $reflection_method->invokeArgs($this->registry, [&$hooks$theme->reveal()]);

    $this->assertEquals($expected$hooks);
  }

  
// @todo Inject the Renderer in https://www.drupal.org/node/2529438.         \Drupal::service('renderer')->render($preprocess_bubbleable);
      }
    }

    // Generate the output using a template.     $render_function = 'twig_render_template';
    $extension = '.html.twig';

    // The theme engine may use a different extension and a different     // renderer.     $theme_engine = $active_theme->getEngine();
    if (isset($theme_engine)) {
      if ($info['type'] != 'module') {
        if (function_exists($theme_engine . '_render_template')) {
          $render_function = $theme_engine . '_render_template';
        }
        $extension_function = $theme_engine . '_extension';
        if (function_exists($extension_function)) {
          $extension = $extension_function();
        }
      }
    }

    
$this->assertFalse($delegatingEngine->supports('template.php'));
    }

    public function testGetExistingEngine()
    {
        $firstEngine = $this->getEngineMock('template.php', false);
        $secondEngine = $this->getEngineMock('template.php', true);

        $delegatingEngine = new DelegatingEngine([$firstEngine$secondEngine]);

        $this->assertSame($secondEngine$delegatingEngine->getEngine('template.php'));
    }

    public function testGetInvalidEngine()
    {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('No engine is able to work with the template "template.php"');
        $firstEngine = $this->getEngineMock('template.php', false);
        $secondEngine = $this->getEngineMock('template.php', false);

        $delegatingEngine = new DelegatingEngine([$firstEngine$secondEngine]);
        $delegatingEngine->getEngine('template.php');
    }

    public function __construct(array $engines = [])
    {
        foreach ($engines as $engine) {
            $this->addEngine($engine);
        }
    }

    public function render(string|TemplateReferenceInterface $name, array $parameters = []): string
    {
        return $this->getEngine($name)->render($name$parameters);
    }

    /** * @return void */
    public function stream(string|TemplateReferenceInterface $name, array $parameters = [])
    {
        $engine = $this->getEngine($name);
        if (!$engine instanceof StreamingEngineInterface) {
            throw new \LogicException(sprintf('Template "%s" cannot be streamed as the engine supporting it does not implement StreamingEngineInterface.', $name));
        }

        
Home | Imprint | This part of the site doesn't use cookies.