Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Error.php

function Error::guessTemplateInfo

1 call to Error::guessTemplateInfo()
Error::guess in vendor/twig/twig/src/Error/Error.php

File

vendor/twig/twig/src/Error/Error.php, line 166

Class

Error
Twig base exception.

Namespace

Twig\Error

Code

private function guessTemplateInfo() : void {
    $template = null;
    $templateClass = null;
    $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT);
    foreach ($backtrace as $trace) {
        if (isset($trace['object']) && $trace['object'] instanceof Template) {
            $currentClass = \get_class($trace['object']);
            $isEmbedContainer = null === $templateClass ? false : str_starts_with($templateClass, $currentClass);
            if (null === $this->name || $this->name == $trace['object']->getTemplateName() && !$isEmbedContainer) {
                $template = $trace['object'];
                $templateClass = \get_class($trace['object']);
            }
        }
    }
    // update template name
    if (null !== $template && null === $this->name) {
        $this->name = $template->getTemplateName();
    }
    // update template path if any
    if (null !== $template && null === $this->sourcePath) {
        $src = $template->getSourceContext();
        $this->sourceCode = $src->getCode();
        $this->sourcePath = $src->getPath();
    }
    if (null === $template || $this->lineno > -1) {
        return;
    }
    $r = new \ReflectionObject($template);
    $file = $r->getFileName();
    $exceptions = [
        $e = $this,
    ];
    while ($e = $e->getPrevious()) {
        $exceptions[] = $e;
    }
    while ($e = array_pop($exceptions)) {
        $traces = $e->getTrace();
        array_unshift($traces, [
            'file' => $e->getFile(),
            'line' => $e->getLine(),
        ]);
        while ($trace = array_shift($traces)) {
            if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
                continue;
            }
            foreach ($template->getDebugInfo() as $codeLine => $templateLine) {
                if ($codeLine <= $trace['line']) {
                    // update template line
                    $this->lineno = $templateLine;
                    return;
                }
            }
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal