Fix return type of FormatterInterface::settingsSummary

Created on 9 June 2024, 4 months ago
Updated 26 June 2024, 4 months ago

Problem/Motivation

The phpdoc \Drupal\Core\Field\FormatterInterface::settingsSummary currently specifies string[] as the return type, but most implementations use TranslatableMarkup. At phpstan level 7 this results in the following error:

Method Drupal\mymodule\Plugin\Field\FieldFormatter\MyModuleFormatter::settingsSummary() should return array<string> but returns array<Drupal\Core\StringTranslation\TranslatableMarkup|string>.

Steps to reproduce

Proposed resolution

Change return type doc:
@return array<string|\Stringable>

Or if we want to be more specific:
@return array<string|\Drupal\Core\StringTranslation\TranslatableMarkup>

Or somewhere in between:
@return array<string|\Drupal\Component\Render\MarkupInterface>

Remaining tasks

Determine which of the proposed resolutions to use. Currently the summary is accessed in \Drupal\field_ui\Form\EntityDisplayFormBase::buildFieldRow which is passed to \Drupal\Core\Template\TwigExtension::safeJoin. This calls \Drupal\Core\Template\TwigExtension::escapeFilter which has special handling for MarkupInterface, and a fallback for \Stringable to apply auto escaping. Seems reasonable to me that we should all the broader \Stringable.

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

10.3 ✨

Component
FieldΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

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