Warning: foreach() argument must be of type array|object, null given in /app/htdocs/core/lib/Drupal/Core/Render/Element/Checkboxes.php on line 113

Created on 19 July 2023, 11 months ago
Updated 18 January 2024, 5 months ago

Problem/Motivation

With Drupal 10.1 and siteimprove 2.0.1, each installed by composer, freshly installed but not yet configured, the following warning was given on page /admin/config/system/siteimprove. Warning persists after cron run, cache flush, adding config options, etc.

Warning: foreach() argument must be of type array|object, null given in /app/htdocs/core/lib/Drupal/Core/Render/Element/Checkboxes.php on line 113

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom richardhobbs

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @richardhobbs
  • Status changed to Needs work 10 months ago
  • 🇩🇰Denmark bartvig

    I'm going to need some more information. I can't reproduce the error on a freshly installed Drupal 10.1.0 or Drupal 10.1.2.

    The only way I can see that any checkboxes in SettingsForm.php could be null and thus producing the mentioned error, is if node_type_get_names(); returns null, and the documentation says it returns string[], so I'm puzzled as to how you can get this error.

    If either there are no node types, taxonomy types, or group types (and the group module has been enabled), then all the checkboxes variables will be empty arrays which is fine.

  • 🇫🇮Finland Alexander Tallqvist

    Im getting the same error on Drupal 9.5.9 when I just upgraded the module from version 2.0.0 to 2.0.1. Here is the full output:

    Error message
    Warning: foreach() argument must be of type array|object, null given in Drupal\Core\Render\Element\Checkboxes::valueCallback() (line 113 of core/lib/Drupal/Core/Render/Element/Checkboxes.php).

    Drupal\Core\Render\Element\Checkboxes::valueCallback(Array, , Object)
    call_user_func_array(Array, Array) (Line: 1287)
    Drupal\Core\Form\FormBuilder->handleInputElement('siteimprove_settings_form', Array, Object) (Line: 1005)
    Drupal\Core\Form\FormBuilder->doBuildForm('siteimprove_settings_form', Array, Object) (Line: 1075)
    Drupal\Core\Form\FormBuilder->doBuildForm('siteimprove_settings_form', Array, Object) (Line: 1075)
    Drupal\Core\Form\FormBuilder->doBuildForm('siteimprove_settings_form', Array, Object) (Line: 1075)
    Drupal\Core\Form\FormBuilder->doBuildForm('siteimprove_settings_form', Array, Object) (Line: 579)
    Drupal\Core\Form\FormBuilder->processForm('siteimprove_settings_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: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    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: 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: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    The problem lies in the default values for some of the checkboxes. '#default_value' => $config->get('enabled_content_types') might be returning NULL, which is causing the warning. Applying the patch from the original issue seems to fix the problem for me.

  • Status changed to Fixed 6 months ago
  • 🇩🇰Denmark bartvig

    Fixed in latest dev version.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024