TemplateWrapper example

->getMockBuilder('Drupal\Core\Template\TwigEnvironment')
      ->disableOriginalConstructor()
      ->getMock();

    $template = $this->getMockForAbstractClass(Template::class[$twig], '', TRUE, TRUE, TRUE, ['render']);
    $template
      ->method('render')
      ->willReturn(self::PLUGIN_INFORMATION['body']);

    $twig
      ->method('load')
      ->willReturn(new TemplateWrapper($twig$template));

    return $twig;
  }

}

    public function load($name): TemplateWrapper
    {
        if ($name instanceof TemplateWrapper) {
            return $name;
        }

        return new TemplateWrapper($this$this->loadTemplate($this->getTemplateClass($name)$name));
    }

    /** * Loads a template internal representation. * * This method is for internal use only and should never be called * directly. * * @param string $name The template name * @param int $index The index if it is an embedded template * * @throws LoaderError When the template cannot be found * @throws RuntimeError When a previously generated cache is corrupted * @throws SyntaxError When an error occurred during compilation * * @internal */
Home | Imprint | This part of the site doesn't use cookies.