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

Matroskeen created an issue. See original summary.

matroskeen’s picture

Issue summary: View changes

  • arshadkhan35 committed 19b81f0 on 1.0.x
    Issue #3182725: Provide configuration schema and default configuration...
arshadkhan35’s picture

Thanks @matroskeen for reporting the issue, fixed.

arshadkhan35’s picture

Status: Active » Fixed
arshadkhan35’s picture

Status: Fixed » Closed (fixed)
sahil432’s picture

Category: Task » Bug report

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