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
- Install Drupal 10.1.1 and Rabbit Hole 2.0.0-alpha3.
- Go to the login page (/user/login).
Proposed resolution
I'll attach a patch asap.
Comments
Comment #2
jsutta CreditAttribution: jsutta commentedPatch attached!
Comment #3
matroskeenI'm trying to understand how this is possible. The 2nd parameter of
array_map
call is$entity_types
, which containsenabled_entity_types
property ofrabbit_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.
Comment #4
matroskeenComment #5
taraskorpachI 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.
Comment #6
jsutta CreditAttribution: jsutta commentedAgreed. I removed the patch and my site's working just fine. Most likely just user error on my part. We can close this issue.
Comment #7
matroskeenThanks for the confirmation! Closing it
Comment #8
DiDebruI 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.
Comment #9
aadeshvermaster@gmail.com CreditAttribution: aadeshvermaster@gmail.com at Wipro Technologies commentedI 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
Comment #10
denes.szabo CreditAttribution: denes.szabo commentedI 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.
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.
Comment #11
matroskeenI wonder how the module hook implementation is being called if the module is not installed?
Comment #12
denes.szabo CreditAttribution: denes.szabo commented@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.
Comment #13
K3vin_nl CreditAttribution: K3vin_nl commentedJust want to confirm that #2 3375025-2.patch fixed the issue for us.