- Issue created by @gapple
- ๐ฎ๐ณIndia rajeevkumar
To update the
formatMultipleViolationsMessage()
method to maintain compatibility with both older and newer versions of Drupal core, you can adjust the return type to\Stringable
and handle the MarkupInterface type from the parent. Hereโs the updated code:protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): Stringable { $parent = parent::formatMultipleViolationsMessage($form_element_name, $violations); if ($parent instanceof TranslatableMarkup) { return $parent; } else { // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString return $this->t((string) $parent); } }
This is a broader type that includes MarkupInterface, making it compatible with the newer core return type.
If your code references
\Drupal\update\UpdateSettingsForm
, make sure itsformatMultipleViolationsMessage()
method is updated with the same logic to maintain consistency. - Merge request !10173Resolve #3481331 "Configformbaseformatmultipleviolationsmessage return type" โ (Open) created by rajeevkumar
- ๐ฎ๐ณIndia rajeevkumar
The code ensures compatibility with environments where
\Stringable
might not be explicitly implemented or reliably checked. For example, if there are inconsistencies in extending\Stringable
(e.g., in older or custom implementations), this safeguard ensures the return type is met.
By explicitly handling\Stringable
compatibility, the fallback toTranslatableMarkup
guarantees compliance with the methodโs return signature even in edge cases.
While I acknowledge that the base class is expected to comply with the return type, the explicit check is intentional to ensure compatibility, clarity, and robustness in a dynamic and customizable system like Drupal.