Problem/Motivation
On new installs when you enter on settings page it's expecting the config "bypass_role" that hasn't been created and a warning is showed:
Warning: Invalid argument supplied for foreach() in Drupal\Core\Render\Element\Checkboxes::valueCallback() (line 100 of core/lib/Drupal/Core/Render/Element/Checkboxes.php).
Drupal\Core\Render\Element\Checkboxes::valueCallback(Array, , Object)
call_user_func_array(Array, Array) (Line: 1277)
Drupal\Core\Form\FormBuilder->handleInputElement('pages_restriction_admin_settings', Array, Object) (Line: 1000)
Drupal\Core\Form\FormBuilder->doBuildForm('pages_restriction_admin_settings', Array, Object) (Line: 1070)
Drupal\Core\Form\FormBuilder->doBuildForm('pages_restriction_admin_settings', Array, Object) (Line: 1070)
Drupal\Core\Form\FormBuilder->doBuildForm('pages_restriction_admin_settings', Array, Object) (Line: 574)
Drupal\Core\Form\FormBuilder->processForm('pages_restriction_admin_settings', Array, Object) (Line: 320)
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: 564)
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: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
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: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)Steps to reproduce
Install module and access the settings page.
Proposed resolution
It can be resolved by:
1- validating is the config exists before use the config or
2- create the config empty for new installs
3- Or both solutions...
I created a patch following the second option.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3259416-2.patch | 292 bytes | wesleyl |
Comments
Comment #2
wesleyl commentedHere is the patch
Comment #3
victoria-marina commentedI'll review this.
Comment #4
victoria-marina commentedI've installed module, reproduced the issue, applied the patch and tested it again. Everything is ok!
Comment #5
renatog commentedIt totally makes sense. Thank you so much @wesleyl for your solution and @victoria-marina for your review, Great job!
Comment #7
renatog commentedMoved to the dev branch.
Thank you so much
Comment #8
renatog commentedI've created a new release with this: https://www.drupal.org/project/pages_restriction/releases/8.x-1.5
To use in our projects we can run:
Thanks a lot