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 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 ...Comment #16
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #17
smustgrave commentedSeems like a valid task actually.