Problem/Motivation
The Token::replace()
method supports a $options['callback']
parameter to allow modules to provide token replacements. However, the documentation previously referred to this as a “function”, even though any valid PHP callable (such as object method or closure) is technically supported.
This lack of clarity caused confusion, especially during the Drupal 8 port of the Token contrib module, where object-oriented approaches (e.g., service classes with methods) became more common.
Steps to reproduce
- Use a service class method (e.g.,
[$this, 'myMethod']
) as thecallback
forToken::replace()
. - Read the documentation and note it refers to it as a "function".
- This can cause a developer to question if non-function callables are supported or behave correctly.
Proposed resolution
Clarify the callback
parameter in the docblock of \Drupal\Core\Utility\Token::replace()
to specify that any callable
is accepted. This brings the documentation in line with actual behavior.
This is a documentation-only change and does not alter any existing logic or behavior.
Remaining tasks
Update docblock forToken::replace()
to reflect callable support- Review and approval
User interface changes
None.
API changes
None. The method already accepts any callable. This change is to the documentation only.
Data model changes
None.
Release notes snippet
Clarified documentation for the Token::replace()
method to state that any valid callable
can be passed via the $options['callback']
parameter.