Problem/Motivation
There is a warning on admin/config/services/jsonapi/role_access page when roles were not selected yet.
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: 1285)
Drupal\Core\Form\FormBuilder->handleInputElement('jsonapi_role_access_form', Array, Object) (Line: 1002)
Drupal\Core\Form\FormBuilder->doBuildForm('jsonapi_role_access_form', Array, Object) (Line: 1072)
Drupal\Core\Form\FormBuilder->doBuildForm('jsonapi_role_access_form', Array, Object) (Line: 575)
Drupal\Core\Form\FormBuilder->processForm('jsonapi_role_access_form', Array, Object) (Line: 321)
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: 573)
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: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
This happens because the configuration object does not exist yet, and this statement returns NULL:
$config->get('roles'), which is not correct.
Steps to reproduce
1) Install the module;
2) Visit configuration page /admin/config/services/jsonapi/role_access;
Proposed resolution
Add configuration schema and default configuration (config/install) into the module;
tps://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemame...
With those changes, the initial module installation will create a configuration object in your database and the warning will disappear.
Comments
Comment #2
matroskeenComment #4
arshadkhan35 commentedThanks @matroskeen for reporting the issue, fixed.
Comment #5
arshadkhan35 commentedComment #6
arshadkhan35 commentedComment #7
sahil432 commentedIdeally we should not provide access to authenticated user as it is mention in config install.
Problem :- After installing module if we have multiple roles only 2 random roles are coming based on role index which is written based on assumption in JS file.