By geek-merlin on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.3.x
Introduced in version:
11.3.0
Issue links:
Description:
The access of Twig templates to object methods can now allowed by the TwigAllowed attribute.
Example:
class AttributeAllowTestClass {
#[\Drupal\Core\Template\Attribute\TwigAllowed]
public function allowed(): string {
return __METHOD__;
}
public function notAllowed(): string {
return __METHOD__;
}
// Still allowed, but soon deprecated.
public function getFoo(): string {
return 'foo';
}
}
Note that
- The legacy behavior of allowing methods with magic prefixes is still working, but may be deprecated in the future.
- The legacy method of adjusting said patterns via settings.php is still working, but discouraged.
Impacts:
Module developers
Themers