Add expression-based conditions to enable or disable Twig hookables - #385
Merged
Merged
Conversation
loic425
marked this pull request as draft
September 24, 2026 10:10
Prometee
reviewed
Sep 24, 2026
loic425
force-pushed
the
twig-hookable-condition
branch
from
September 24, 2026 12:37
f6e142f to
525d275
Compare
Introduce a new 'condition' configuration option for hookables. The value is an Expression Language expression prefixed with '@=' that is evaluated at runtime against the hook context. The hookable is rendered only when the expression returns true. Conditions are linted at the application boot to fail fast on invalid expressions, and evaluated by a new HookableConditionChecker injected into the HookRenderer. 'enabled' remains a static boot-time flag, keeping the two mechanisms clearly separated.
loic425
force-pushed
the
twig-hookable-condition
branch
from
September 24, 2026 12:41
525d275 to
fc2d8c0
Compare
loic425
marked this pull request as ready for review
September 24, 2026 12:44
Prometee
approved these changes
Sep 24, 2026
TheMilek
approved these changes
Sep 25, 2026
diimpp
requested changes
Sep 25, 2026
| { | ||
| $condition = $hookable['condition'] ?? null; | ||
|
|
||
| if (null === $condition || !defined(Parser::class . '::IGNORE_UNKNOWN_VARIABLES')) { |
Member
There was a problem hiding this comment.
This defined early return essentially disables lint for older than SF 7.1.
::IGNORE_UNKNOWN_VARIABLES was introduced in 7.1 and only changes method signature, not behaviour. Previosly we should have supplied null for the same result.
So something like this instead of early return.
- $expressionLanguage->lint(substr($condition, 2), [], Parser::IGNORE_UNKNOWN_VARIABLES);
+ $expression = substr($condition, 2);
+
+ if (defined(Parser::class . '::IGNORE_UNKNOWN_VARIABLES')) {
+ $expressionLanguage->lint(
+ $expression,
+ [],
+ Parser::IGNORE_UNKNOWN_VARIABLES
+ );
+ } else {
+ $expressionLanguage->lint(
+ $expression,
+ null
+ );
+ }
Member
Author
There was a problem hiding this comment.
I agree, but I think we still need the "try/catch" to have a better error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce a new 'condition' configuration option for hookables. The value is an Expression Language expression prefixed with '@=' that is evaluated at runtime against the hook context. The hookable is rendered only when the expression returns true.
Conditions are linted at the application boot to fail fast on invalid expressions, and evaluated by a new HookableConditionChecker injected into the HookRenderer. 'enabled' remains a static boot-time flag, keeping the two mechanisms clearly separated.