TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 431 of core/modules/menu_ui/menu_ui.module)

Created on 6 February 2024, 4 months ago
Updated 7 February 2024, 4 months ago

Problem/Motivation

Manually deleting the "Menu settings" form element throws the following error when creating a content:

The website encountered an unexpected error. Try again later.

TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 431 of core/modules/menu_ui/menu_ui.module).
menu_ui_form_node_type_form_builder('node_type', Object, Array, Object)
call_user_func_array('menu_ui_form_node_type_form_builder', Array) (Line: 307)
Drupal\Core\Entity\EntityForm->buildEntity(Array, Object) (Line: 171)
Drupal\Core\Entity\EntityForm->afterBuild(Array, Object)
call_user_func_array(Array, Array) (Line: 1084)
Drupal\Core\Form\FormBuilder->doBuildForm('node_type_add_form', Array, Object) (Line: 579)
Drupal\Core\Form\FormBuilder->processForm('node_type_add_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 177)
Drupal\static_preview_gatsby_instant\EventSubscriber\PreviewControllerWrapperSubscriber->wrapControllerExecutionInPreviewHandler(Object, Array, Object) (Line: 113)
Drupal\static_preview_gatsby_instant\EventSubscriber\PreviewControllerWrapperSubscriber->Drupal\static_preview_gatsby_instant\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

This is because the value of $form_state "menu_options" is NULL when processed in the PHP function array_filter().

Steps to reproduce

  1. Remove "Menu settings" form element from all node forms (preg_match('/node_(.*)_form/', $form_id) and unset($form['menu']);)
  2. Add content type and Save and manage fields.

Proposed resolution

Shielding the processing of $form_state->getValue('menu_options') within the PHP function array_filter() whether or not it is necessary to remove "Menu settings" will add robustness to the code.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Menu systemΒ  β†’

Last updated 5 days ago

Created by

πŸ‡ͺπŸ‡ΈSpain enchufe Madrid

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024