Wrong return type in hook_field_formatter_third_party_settings_form
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3532973. --> Reported by: [willids](https://www.drupal.org/user/3553550) Related to !22 >>> <p>Getting this error when I try to view the display form (content type)</p> <p>Structure --&gt; Content Types --&gt; Content Type -- &gt; Manage Display</p> <p>===========================<br> The website encountered an unexpected error. Try again later.</p> <p>TypeError: Unsupported operand types: array + null in Drupal\field_ui\Form\EntityViewDisplayEditForm-&gt;{closure:Drupal\field_ui\Form\EntityViewDisplayEditForm::thirdPartySettingsForm():164}() (line 166 of core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php).</p> <p>Drupal\Core\Extension\ModuleHandler-&gt;invokeAllWith('field_formatter_third_party_settings_form', Object) (Line: 162)<br> Drupal\field_ui\Form\EntityViewDisplayEditForm-&gt;thirdPartySettingsForm(Object, Object, Array, Object) (Line: 459)<br> Drupal\field_ui\Form\EntityDisplayFormBase-&gt;buildFieldRow(Object, Array, Object) (Line: 41)<br> Drupal\field_ui\Form\EntityViewDisplayEditForm-&gt;buildFieldRow(Object, Array, Object) (Line: 213)<br> Drupal\field_ui\Form\EntityDisplayFormBase-&gt;form(Array, Object) (Line: 107)<br> Drupal\Core\Entity\EntityForm-&gt;buildForm(Array, Object)<br> call_user_func_array(Array, Array) (Line: 528)<br> Drupal\Core\Form\FormBuilder-&gt;retrieveForm('entity_view_display_edit_form', Object) (Line: 279)<br> Drupal\Core\Form\FormBuilder-&gt;buildForm(Object, Object) (Line: 73)<br> Drupal\Core\Controller\FormController-&gt;getContentResult(Object, Object)<br> call_user_func_array(Array, Array) (Line: 123)<br> Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}() (Line: 622)<br> Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 121)<br> Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)<br> Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}() (Line: 183)<br> Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 76)<br> Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 53)<br> Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 48)<br> Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 28)<br> Drupal\Core\StackMiddleware\ContentLength-&gt;handle(Object, 1, 1) (Line: 116)<br> Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 90)<br> Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 57)<br> Drupal\advban\AdvbanMiddleware-&gt;handle(Object, 1, 1) (Line: 50)<br> Drupal\ban\BanMiddleware-&gt;handle(Object, 1, 1) (Line: 48)<br> Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 51)<br> Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 53)<br> Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle(Object, 1, 1) (Line: 49)<br> Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware-&gt;handle(Object, 1, 1) (Line: 51)<br> Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 715)<br> Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)</p> <p>=============================================================</p> <p>This is what appears in error log on the hosting</p> <p>[27-Jun-2025 16:06:22 Europe/London] Uncaught PHP Exception TypeError: "Unsupported operand types: array + null" at /home/DOMAIN/public_html/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php line 166</p> <p>==========================================================</p> <p>File Code</p> <p>protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {<br> $settings_form = [];<br> // Invoke hook_field_formatter_third_party_settings_form(), keying resulting<br> // subforms by module name.<br> $this-&gt;moduleHandler-&gt;invokeAllWith(<br> 'field_formatter_third_party_settings_form',<br> function (callable $hook, string $module) use (&amp;$settings_form, &amp;$plugin, &amp;$field_definition, &amp;$form, &amp;$form_state) {<br> $settings_form[$module] = ($settings_form[$module] ?? []) + ($hook(<br> $plugin, /** &lt;-- 166 */<br> $field_definition,<br> $this-&gt;entity-&gt;getMode(),<br> $form,<br> $form_state,<br> )) ?? []; /** &lt;-- 171 has red x next to editor on hosting */<br> }<br> );<br> return $settings_form;<br> }</p> <p>Removed Linked Field, and this disappears. installed and it appears</p> <p>Drupal 11.2.2<br> PHP 8.4</p>
issue