Problem/Motivation
After the change in
#3250429: The existing template implementation seems to bypass some core field template functionality β
, PHP warnings are logged for content using this field type when it is used as the source for content provided by the Metatag module:
User error: "content_attributes" is an invalid render array key in Drupal\Core\Render\Element::children() (line 98 of core/lib/Drupal/Core/Render/Element.php).
field_tokens('entity', Array, Array, Array, Object)
call_user_func_array(Object, Array) (Line: 426)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'field') (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object) (Line: 433)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 357)
Diagnosis
Based on the error message, it appears that the Metatag module's attempt to extract tokens from this field fail. In general, the "invalid render array key" in Drupal indicates that a render element key is not preceded by a '#'. If it is not preceded by '#', Drupal assumes it contains and array of renderable element children. In other words, the '#' indicates that the element is renderable on its own and has no children.
Steps to reproduce
1. Create a field on a node type using this module's Horizontal Tabs field type.
2. Add a definition for this node type using the Metatag module, such as using [node:field_FIELDNAME:0]
for the Open Graph Description
3. View the node. PHP notices will render on every page load.
Proposed resolution
Refactor the keys for `content_attributes`, `link_attributes` and `header` to contain valid Drupal render array, as indicated by containing an array keyed by the #markup element:
https://www.drupal.org/docs/drupal-apis/render-api/render-arrays#properties β
Remaining tasks
User interface changes
API changes
Data model changes