TypeError: Drupal\Core\Utility\Token::replacePlain(): Argument #1 ($plain) must be of type string, null given

Created on 19 March 2025, 21 days ago

Problem/Motivation

On 9.1.1, when viewing a specific node with Layout Builder or editing Layout Builder for that node, we're seeing the following error:
TypeError: Drupal\Core\Utility\Token::replacePlain(): Argument #1 ($plain) must be of type string, null given, called in /web/modules/contrib/patternkit/src/Plugin/PatternFieldProcessor/TokenProcessor.php on line 108 in Drupal\Core\Utility\Token->replacePlain() (line 209 of /web/core/lib/Drupal/Core/Utility/Token.php).

The issue seems to stem from the TokenProcessor->apply having a NULL value instead of a string for the second param:

Drupal\patternkit\Plugin\PatternFieldProcessor\TokenProcessor->apply(Object, NULL, Array, Object) (Line: 158)
Drupal\patternkit\PatternFieldProcessorPluginManager->applyProcessors(Object, NULL, Array, Array, Object)
call_user_func(Array, Object, NULL, Array, Array, Object) (Line: 198)
Drupal\patternkit\PatternFieldProcessorPluginManager->traverseSchema(...)

Proposed resolution

Adding to a condition to check that the value is a string in TokenProcessor::applies() to confirm the value type would probably fix it: https://git.drupalcode.org/project/patternkit/-/blob/9.1.x/src/Plugin/Pa...

public function applies(SchemaContract $propertySchema, $propertyValue = NULL): bool {
  return property_exists($propertySchema, 'type')
    && $propertySchema->type == 'string'
    && is_string($propertyValue);
}
🐛 Bug report
Status

Active

Version

9.1

Component

Module Core

Created by

🇺🇸United States firewaller

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024