Problem/Motivation
After updating a site to Drupal 11, the Message Recipient UI fails with a fatal error when opening the Recipients Collectors configuration form.
Drupal 11 introduced stricter typing for Drupal\Component\Utility\Html::escape(), which now requires a plain string as its argument. The Message Recipient module currently passes a TranslatableMarkup object directly to Html::escape(), resulting in a TypeError.
TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup given, called in /modules/contrib/message_recipient/src/RecipientsCollectorManager.php on line 49 Drupal\Component\Utility\Html::escape() Drupal\message_recipient\RecipientsCollectorManager->getDefinitionsListOptionsGroupedByCategory() Drupal\message_recipient_ui\Form\RecipientsCollectorsForm->buildForm()
Steps to reproduce
Install Message Recipient on a Drupal 11 site.
Navigate to the Message Recipient UI configuration page that displays recipient collectors.
Open the form that triggers RecipientsCollectorsForm::buildForm().
Proposed resolution
Render the TranslatableMarkup object before passing it to Html::escape().
Alternatively, cast/render the value to a string before calling Html::escape().
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | after.PNG | 21.23 KB | angel_devoeted |
| #4 | before.PNG | 6.59 KB | angel_devoeted |
| #2 | 3593859-fix-d11-html-escape-translatablemarkup-typeerror-2.patch | 802 bytes | peter_serfozo |
Comments
Comment #2
peter_serfozo commentedComment #3
peter_serfozo commentedComment #4
angel_devoeted commentedTested patch on a clean Drupal 11 environment via DrupalPod.
Opening the recipients collectors form initially throws a fatal
TypeErrorinHtml::escape(). With the patch applied, the form loads successfully without any issues and logs remain clean.The fix looks solid.
@peter_serfozo, if possible, please consider converting this patch into a Merge Request.
Comment #5
shank115 commentedCan confirm, patch worked for me as well. Thanks!!