TypeError: array_map(): Argument #2 ($array) must be of type array, null given in array_map()

Created on 17 July 2023, about 1 year ago
Updated 12 February 2024, 8 months ago

Problem/Motivation

On a fresh install of Drupal 10.1.1 and Rabbit Hole 2.0.0-alpha3, I'm seeing the following error on the login page:

The website encountered an unexpected error. Please try again later.

TypeError: array_map(): Argument #2 ($array) must be of type array, null given in array_map() (line 41 of modules/contrib/rabbit_hole/rabbit_hole.module).
rabbit_hole_form_alter(Array, Object, 'user_login_form') (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'user_login_form') (Line: 840)
Drupal\Core\Form\FormBuilder->prepareForm('user_login_form', Array, Object) (Line: 284)
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: 583)
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: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
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: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Install Drupal 10.1.1 and Rabbit Hole 2.0.0-alpha3.
  2. Go to the login page (/user/login).

Proposed resolution

I'll attach a patch asap.

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇺🇸United States jsutta United States

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

Comments & Activities

  • Issue created by @jsutta
  • 🇺🇸United States jsutta United States

    Patch attached!

  • Status changed to Postponed about 1 year ago
  • 🇺🇦Ukraine Matroskeen 🇺🇦 Ukraine, Lutsk

    I'm trying to understand how this is possible. The 2nd parameter of array_map call is $entity_types, which contains enabled_entity_types property of rabbit_hole.settings config.

    There is a default value for this property defined in config/install/rabbit_hole.settings.yml. So how did you manage to install the module without applying the default configuration?

    Can you check please?

  • Status changed to Postponed: needs info about 1 year ago
  • 🇺🇦Ukraine Matroskeen 🇺🇦 Ukraine, Lutsk
  • 🇺🇦Ukraine taraskorpach Lutsk

    I got the same error while upgrading to D10.1.1. Fortunately, the error is fixed by running a database update. Therefore, the patch is not useful.

  • 🇺🇸United States jsutta United States

    Agreed. I removed the patch and my site's working just fine. Most likely just user error on my part. We can close this issue.

  • Status changed to Closed: cannot reproduce about 1 year ago
  • 🇺🇦Ukraine Matroskeen 🇺🇦 Ukraine, Lutsk

    Thanks for the confirmation! Closing it

  • 🇩🇪Germany DiDebru

    I got this error after upgrading from 9.4 to 10.1.
    I did run all db updates and ended up with an empty setting en/admin/config/content/rabbit-hole and the variable was always null.
    The patch did not solve this but I was able to solve this by overriding the variable with an empty array than I did the config saved removed the workaround and my site works again.

  • I got this error after upgrading from Drupal 9 to 10. After applying Patch https://www.drupal.org/project/rabbit_hole/issues/3375025#comment-15152836 🐛 TypeError: array_map(): Argument #2 ($array) must be of type array, null given in array_map() Closed: cannot reproduce its resolved this error

  • 🇭🇺Hungary Denes.Szabo Hungary

    I got this error also, fresh 10.2.3.

    The problem is: The code suppose the $entity_types is array. It is not if you have not setup the module, its NULL.

    Then the array_map tries to use it as an array.

     $entity_types = \Drupal::config('rabbit_hole.settings')->get('enabled_entity_types') ?? [];
      $affected_bundle_types = array_map(function($entity_type_id) use ($entity_type_manager) {
        return $entity_type_manager->getStorage($entity_type_id)->getEntityType()->getBundleEntityType();
      }, $entity_types);
    

    Quick solution is: $entity_types = \Drupal::config('rabbit_hole.settings')->get('enabled_entity_types') ?? [];

    Same error exists in the src/BehaviorSettingsManager. But there it has been handled similar way alreay in the line 41.

    Patch to fix these issues is attached.

  • Status changed to Needs work 8 months ago
  • 🇺🇦Ukraine Matroskeen 🇺🇦 Ukraine, Lutsk

    The problem is: The code suppose the $entity_types is array. It is not if you have not setup the module, its NULL

    I wonder how the module hook implementation is being called if the module is not installed?

  • 🇭🇺Hungary Denes.Szabo Hungary

    @Matroskeen

    I mean: The rabbit_hole already installed but not configured - the config is empty, the rabbit hole settings form was not submitted - or there was no entity type checked.

    I do not know why sb want this situation, enable the rb, but does not configure it properly, but on my (inherited) site this is the status.

    Whatever: if this config should used in array environment, then it should be an array.

    The empty value default set to array case was already there (I mentioned it before) I just added the default array value to all similar code.

  • 🇳🇱Netherlands K3vin_nl

    Just want to confirm that #2 3375025-2.patch fixed the issue for us.

Production build 0.71.5 2024