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 &ldquo;Add to calendar&rdquo; 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-&gt;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-&gt;getDefinition()<br>Drupal\field_ui\Controller\FieldStorageAddController-&gt;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>&nbsp; -&gt;setLabel(new TranslatableMarkup('Add to calendar'))<br>&nbsp; -&gt;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>&nbsp; -&gt;setLabel(t('Add to calendar'))<br>&nbsp; -&gt;setComputed(TRUE)<br>&nbsp; -&gt;setDisplayConfigurable('view', TRUE)<br>&nbsp; -&gt;setDisplayOptions('view', [<br>&nbsp;&nbsp;&nbsp; 'region' =&gt; 'hidden',<br>&nbsp; ])<br>&nbsp; -&gt;setClass(AddToCalendarItemList::class);</pre> > Related issue: [Issue #3475505](https://www.drupal.org/node/3475505)
issue