bug: #3629878: Debug mode calls non-existent LoggerChannel::dump() and causes a fatal error

Problem

With Devel enabled and Debug Mode checked, evaluateExpression() calls \Drupal::logger('field_token_expression_debug')->dump($debug). LoggerChannel has no dump() method, so saving the entity, or rendering it with Always Evaluate Expression? enabled, ends in a fatal error. The call replaced dpm() in the Drupal 11 upgrade, so 2.0.3 and 2.1.0 are affected.

Changes

  • ExpressionItem and ExpressionItemTrait: the call is replaced with \Drupal::service('devel.dumper')->message($debug, 'Field Token Expression Debug Output'), the service that dpm() wraps. It stays behind the existing moduleExists('devel') check, and the misleading // Use logger()->dump() for debugging. comment is removed.
  • ExpressionItem: the Token Replaced Expression entry now shows the expression before blank spaces are removed, as ExpressionItemTrait already does. Spaces are still stripped from the string passed to EvalMath, so results do not change. Before this, the legacy type showed 3*3 while the 2.x types showed 2 + 2 (this difference predates 2.0.3).

Testing

Drupal 11.4.8, PHP 8.4, Devel 5.5.0, tested with a Drush script that saves a node as user 1:

  1. Before the change: the save fails with Error: Call to undefined method Drupal\Core\Logger\LoggerChannel::dump().
  2. After the change: the node saves, and the original expression, the token replaced expression and the result are shown as a status message for both expression_integer (2 + 2, result 4) and the legacy field_expression type (1 000 + 2, result 1002).
  3. phpcs --standard=Drupal,DrupalPractice reports no errors.

Closes #3629878

Edited by Orkut Murat Yılmaz

Merge request reports

Loading
Loading