Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
It was out of scope for #2396607-31: Allow Views token matching for validation (and remove dead code) but we can add validation to Views UI to prevent saving invalid Twig now that the Views rewrite functionality uses Twig: https://www.drupal.org/node/2404639
Proposed resolution
Add some validation, example code:
try {
$environment->parse($environment->tokenize($templateCode));
} catch (\Twig_Error_Syntax $e) {
// Display validation error.
}
Remaining tasks
- Patch
- Tests
- Review
User interface changes
Validation errors would be displayed.
API changes
TBD
Comments
Comment #1
dawehnerAdding a tag.
+1 for doing it
Comment #2
Fabianx CreditAttribution: Fabianx as a volunteer commentedHowever this is soft-blocked on #2492839: Views replacement token bc layer allows for Twig template injection via arguments, because how else could we say that e.g.:
node/{{ %1 }}
is a valid twig template, while it might be after being replaced with e.g. 1 ...