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 --> Content Types --> Content Type -- > 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->{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->invokeAllWith('field_formatter_third_party_settings_form', Object) (Line: 162)<br>
Drupal\field_ui\Form\EntityViewDisplayEditForm->thirdPartySettingsForm(Object, Object, Array, Object) (Line: 459)<br>
Drupal\field_ui\Form\EntityDisplayFormBase->buildFieldRow(Object, Array, Object) (Line: 41)<br>
Drupal\field_ui\Form\EntityViewDisplayEditForm->buildFieldRow(Object, Array, Object) (Line: 213)<br>
Drupal\field_ui\Form\EntityDisplayFormBase->form(Array, Object) (Line: 107)<br>
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)<br>
call_user_func_array(Array, Array) (Line: 528)<br>
Drupal\Core\Form\FormBuilder->retrieveForm('entity_view_display_edit_form', Object) (Line: 279)<br>
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)<br>
Drupal\Core\Controller\FormController->getContentResult(Object, Object)<br>
call_user_func_array(Array, Array) (Line: 123)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}() (Line: 622)<br>
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)<br>
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}() (Line: 183)<br>
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)<br>
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)<br>
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)<br>
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)<br>
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)<br>
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)<br>
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 57)<br>
Drupal\advban\AdvbanMiddleware->handle(Object, 1, 1) (Line: 50)<br>
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)<br>
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)<br>
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 53)<br>
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 49)<br>
Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle(Object, 1, 1) (Line: 51)<br>
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 715)<br>
Drupal\Core\DrupalKernel->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->moduleHandler->invokeAllWith(<br>
'field_formatter_third_party_settings_form',<br>
function (callable $hook, string $module) use (&$settings_form, &$plugin, &$field_definition, &$form, &$form_state) {<br>
$settings_form[$module] = ($settings_form[$module] ?? []) + ($hook(<br>
$plugin, /** <-- 166 */<br>
$field_definition,<br>
$this->entity->getMode(),<br>
$form,<br>
$form_state,<br>
)) ?? []; /** <-- 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