Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 303290

Token::replace() should document that any kind of callable is allowed

$
0
0

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

  1. Use a service class method (e.g., [$this, 'myMethod']) as the callback for Token::replace().
  2. Read the documentation and note it refers to it as a "function".
  3. 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 for Token::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.


Viewing all articles
Browse latest Browse all 303290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>