Fatal error when enabling Add to Calendar field on Drupal 11: TypeError: Cannot access offset of type Drupal\Core\StringTranslation\TranslatableMarkup
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3550129. -->
Reported by: [badeadrian](https://www.drupal.org/user/3719785)
Related to !4
>>>
<p><strong>Description<br>
</strong><br>
When using the Add to Calendar Field Formatter module on Drupal 11, the site throws a fatal error when attempting to add the “Add to calendar” field to a content type.</p>
<p><strong>Error message:</strong></p>
<pre>An AJAX HTTP error occurred.<br>HTTP Result Code: 500<br>StatusText: 500 Service unavailable (with message)<br><br>TypeError: Cannot access offset of type Drupal\Core\StringTranslation\TranslatableMarkup <br>in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() <br>(core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php line 45)</pre><p><strong>Stack trace excerpt:</strong></p>
<pre>Drupal\Core\Plugin\DefaultPluginManager->getDefinition()<br>Drupal\field_ui\Controller\FieldStorageAddController->getFieldSelectionLinks()</pre><p>This prevents the field from being added via the UI.</p>
<p><strong>Root cause</strong></p>
<p>In add_to_calendar.module, the base field definition uses a manually instantiated TranslatableMarkup object for the label:</p>
<pre>$fields['add_to_calendar'] = BaseFieldDefinition::create('add_to_calendar')<br> ->setLabel(new TranslatableMarkup('Add to calendar'))<br> ->setComputed(TRUE)</pre><p><strong>Solution:</strong><br>
Replace new TranslatableMarkup() with the standard translation API call t():</p>
<pre>$fields['add_to_calendar'] = BaseFieldDefinition::create('add_to_calendar')<br> ->setLabel(t('Add to calendar'))<br> ->setComputed(TRUE)<br> ->setDisplayConfigurable('view', TRUE)<br> ->setDisplayOptions('view', [<br> 'region' => 'hidden',<br> ])<br> ->setClass(AddToCalendarItemList::class);</pre>
> Related issue: [Issue #3475505](https://www.drupal.org/node/3475505)
issue