Problem/Motivation

Page: admin/config/services/jsonapi

The above-mentioned admin page is not loading when config_readonly is active.

Steps to reproduce

To troubleshoot, need to enable readonly locally. Should be able to do this in a local settings file by adding the below code.

$settings['config_readonly'] = TRUE;

Visit admin/config/services/jsonapi it will throw you an error.

TypeError: strstr(): Argument #1 ($haystack) must be of type string, Drupal\Core\Form\ConfigTarget given in strstr() (line 167 of /code/web/modules/contrib/config_readonly/src/EventSubscriber/ReadOnlyFormSubscriber.php).

Proposed resolution

Replacing this code in line 166 from:
if (isset($config['#config_target']))

To
if (isset($config['#config_target']) && is_string($config['#config_target'])) and it is working fine.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

manoj selvan created an issue. See original summary.

jon nunan’s picture

Am getting the same on the JSONAPI route, and a similar but slightly different error on REST endpoint settings.
e.g. admin/config/services/rest/resource/rest_menu_item/edit
gives
> Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array in Drupal\config_readonly\EventSubscriber\ReadOnlyFormSubscriber->getConfigTargetNames() (line 166 of modules/contrib/config_readonly/src/EventSubscriber/ReadOnlyFormSubscriber.php).

sarwan_verma made their first commit to this issue’s fork.

mvonfrie’s picture

I'm getting the exact same error on the admin page admin/reports/updates/settings.

fjgarlin’s picture

Status: Active » Needs review

Same here too. I'm not sure whether that string should be empty or not, but at least the MR prevents the hard error.
Please review.

fjgarlin’s picture

Issue summary: View changes

Given more info about the backtrace in case it's useful:

https://mysite.ddev/admin/config/services/jsonapi

Message	TypeError: strstr(): Argument #1 ($haystack) must be of type string, Drupal\Core\Form\ConfigTarget given in strstr() (line 167 of /app/web/modules/contrib/config_readonly/src/EventSubscriber/ReadOnlyFormSubscriber.php).

Severity	Error

Backtrace	
#0 /app/web/modules/contrib/config_readonly/src/EventSubscriber/ReadOnlyFormSubscriber.php(167): strstr()
#1 /app/web/modules/contrib/config_readonly/src/EventSubscriber/ReadOnlyFormSubscriber.php(82): Drupal\config_readonly\EventSubscriber\ReadOnlyFormSubscriber->getConfigTargetNames()
#2 [internal function]: Drupal\config_readonly\EventSubscriber\ReadOnlyFormSubscriber->onFormAlter()
#3 /app/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#4 /app/web/modules/contrib/config_readonly/config_readonly.module(21): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#5 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(552): config_readonly_form_alter()
#6 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(834): Drupal\Core\Extension\ModuleHandler->alter()
...

daniel.pernold made their first commit to this issue’s fork.

daniel.pernold’s picture

I have committed a patch that checks if the array key `#config_target` is of type `ConfigTarget` and if so, extracts the name from it. I think this is the proper approach since the buttons of the discussed forms then gets correctly disabled.

chandansha’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new332.67 KB
new223.41 KB

I have tested MR 17. Now page accessible.
I move it to RTBC.
THANKS!!

pcate’s picture

+1 RTBC. Patch resolves error on /admin/config/services/jsonapi page.

daniel.pernold’s picture

Another issue has cropped up with the same source, this time with the RestUI module. I'm using this ticket to fix it here.

Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array in Drupal\config_readonly\EventSubscriber\ReadOnlyFormSubscriber->getConfigTargetNames() (line 167 of modules/contrib/config_readonly/src/EventSubscriber/ReadOnlyFormSubscriber.php).

Drupal\config_readonly\EventSubscriber\ReadOnlyFormSubscriber->onFormAlter(Object, 'config_readonly_form_event', Object)
call_user_func(Array, Object, 'config_readonly_form_event', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'config_readonly_form_event') (Line: 21)
config_readonly_form_alter(Array, Object, 'restui') (Line: 552)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'restui') (Line: 834)
Drupal\Core\Form\FormBuilder->prepareForm('restui', Array, Object) (Line: 285)
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: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->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: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Patch in this issue fork:

https://git.drupalcode.org/issue/config_readonly-3469854/-/commit/12ac22...

daniel.pernold’s picture

Hi guys, what about to merge this issue? It is tested very well from our side in many projects.

lisotton’s picture

I had the same with with Stage File Proxy and patch provided in the MR resolved the problem.

RTBC +1

daniel.pernold’s picture

@Manoj_Selvan or any other maintainer: Tested this in a couple of projects over the last 7 months, no problems with the change in the MR encountered on our side. Seems very safe to merge.

guedressel’s picture

RTBC +1

Thanks @daniel.pernold 🙌

bdanin’s picture

This is working, I wish it would make its way into a release!

trackleft2’s picture

StatusFileSize
new1.44 KB

I am using the patch from the related issue, but attaching a static version of the merge request here instead of relying on the dynamic .diff URL.

This ensures the patch contents remain fixed and reviewable over time. The dynamic diff link can change if the merge request is updated, and since anyone with a Drupal.org account can modify it, including a static patch here avoids that risk and allows others to safely apply the same tested fix.

Fixes a WSOD caused by config_readonly when accessing certain configuration forms (notably XML Sitemap bundle settings for me) while using a staged configuration workflow.