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

Breadcrumb

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

function SyntaxError::addSuggestions

Tweaks the error message to include suggestions.

Parameters

string $name The original name of the item that does not exist:

array $items An array of possible items:

File

vendor/twig/twig/src/Error/SyntaxError.php, line 28

Class

SyntaxError
\Exception thrown when a syntax error occurs during lexing or parsing of a template.

Namespace

Twig\Error

Code

public function addSuggestions(string $name, array $items) : void {
    $alternatives = [];
    foreach ($items as $item) {
        $lev = levenshtein($name, $item);
        if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
            $alternatives[$item] = $lev;
        }
    }
    if (!$alternatives) {
        return;
    }
    asort($alternatives);
    $this->appendMessage(\sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives))));
}
RSS feed
Powered by Drupal