public function TagFormBase::templateError in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 src/Form/TagFormBase.php \Drupal\xbbcode\Form\TagFormBase::templateError()
Render the code of a broken template with line numbers.
Parameters
\Twig\Error\Error $exception: The twig error for an inline template.
Return value
array Render array showing the code with the error's line highlighted.
1 call to TagFormBase::templateError()
- TagFormBase::form in src/
Form/ TagFormBase.php - Gets the actual form array to be built.
File
- src/
Form/ TagFormBase.php, line 210
Class
- TagFormBase
- Base form for custom tags.
Namespace
Drupal\xbbcode\FormCode
public function templateError(TwigError $exception) : array {
$source = $exception
->getSourceContext();
$code = $source ? $source
->getCode() : '';
$lines = explode("\n", $code);
// Remove the inline template header.
array_shift($lines);
$number = $exception
->getTemplateLine() - 2;
$output = [
'#prefix' => '<pre class="template">',
'#suffix' => '</pre>',
];
foreach ($lines as $i => $line) {
$output[$i] = [
'#prefix' => '<span>',
'#suffix' => "</span>\n",
'#markup' => new HtmlEscapedText($line),
];
}
$output[$number]['#prefix'] = '<span class="line-error">';
return $output;
}