Today I updated the Content Lock module from 8.x-1.0-alpha4 to 8.x-1.0-alpha5 and I'm getting the following warning on editing nodes:

Warning: in_array() expects parameter 2 to be array, null given in Drupal\content_lock\ContentLock\ContentLock->isJsLock() (line 597 of modules/contrib/content_lock/src/ContentLock/ContentLock.php).
Drupal\content_lock\ContentLock\ContentLock->isJsLock('node') (Line: 91)
content_lock_form_alter(Array, Object, 'node_article_edit_form') (Line: 501)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'node_article_edit_form') (Line: 830)
Drupal\Core\Form\FormBuilder->prepareForm('node_article_edit_form', Array, Object) (Line: 272)
Drupal\Core\Form\FormBuilder->buildForm('node_article_edit_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
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}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I'm also getting the following warning on the module configuration page at /admin/config/content/content_lock:

Warning: in_array() expects parameter 2 to be array, null given in Drupal\content_lock\Form\ContentLockSettingsForm->buildForm() (line 169 of modules/contrib/content_lock/src/Form/ContentLockSettingsForm.php).
Drupal\content_lock\Form\ContentLockSettingsForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('content_lock_settings_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('content_lock_settings_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
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}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Comments

jcmartinez created an issue. See original summary.

jcmartinez’s picture

In addition, when submitting the configuration form for this module you get similar errors.

Warning: in_array() expects parameter 2 to be array, null given in Drupal\content_lock\Form\ContentLockSettingsForm->submitForm() (line 246 of modules/contrib/content_lock/src/Form/ContentLockSettingsForm.php).

and

Warning: in_array() expects parameter 2 to be array, null given in Drupal\content_lock\Form\ContentLockSettingsForm->submitForm() (line 256 of modules/contrib/content_lock/src/Form/ContentLockSettingsForm.php).

jcmartinez’s picture

In a few places this module uses the PHP in_array() function to check for a value inside of an array. This function expects that the second parameter is an array however; I found that in some cases the value of the second parameter is NULL which produces the PHP warning.

I've created a patch that checks whether the value is NULL and, if it is, changes the value to an empty array before it is used by the in_array() function. If the value is NOT NULL then it stays unaltered.

Hope this helps.

pegasus360’s picture

I encountered the same error.
However when I tried to use your patch (via terminal CLI) it did not apply.
It could not find a file patch on Line 5
I also tried to uninstall the module but I had no success there either.

chr.fritsch’s picture

Status: Active » Fixed

Thanks @jcmartinez.

That's the reason why we need more test coverage...

Status: Fixed » Closed (fixed)

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