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.

Tag1 Consulting supports Drupal.Tag1 logo

Comments

jsutta created an issue. See original summary.

jsutta’s picture

FileSize
3.42 KB

Patch attached!

matroskeen’s picture

Status: Active » Postponed

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? The thing is that Drupal doesn't provide a way to set a default config value in runtime, so we have to trust what we have in the config storage. In this particular case, we expect this property to be available. If there are no enabled entity types, it should be empty array.

matroskeen’s picture

Status: Postponed » Postponed (maintainer needs more info)
taraskorpach’s picture

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.

jsutta’s picture

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.

matroskeen’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Thanks for the confirmation! Closing it

DiDebru’s picture

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.

aadeshvermaster@gmail.com’s picture

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 its resolved this error

denes.szabo’s picture

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.

matroskeen’s picture

Status: Closed (cannot reproduce) » Needs work

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?

denes.szabo’s picture

@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.

K3vin_nl’s picture

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