I get a fatal error when I enable the read only mode, as described in the README.
The error is about function _readonlymode_form_list_check expecting the second argument to be an Array. Instead a string is given.
Issue fork readonlymode-3115119
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:
- 3115119-additional-forms-config-not-array
changes, plain diff MR !4
Comments
Comment #2
eldrupalista commentedThis patch solves the problem.
Comment #3
eldrupalista commentedComment #4
plopescThis patch looks good and it does the job. Marking as RTBC.
Comment #5
milos.kroulik commentedI applied the patch using composer like this:
But when I open page with a webform block as an anonymous user, I get this fatal error:
So it seems that this patch is actually causing the problem. Can try to replicate my use case, please?
Comment #6
milos.kroulik commentedComment #7
drupal.ninja03 commentedI am unable to reproduce this error after installing the module. Can someone provide the steps to reproduce?
Comment #8
epapaniko commentedI've encountered this, as well. It occurs on pages with forms when installing the module without having altered its settings via the UI or settings.php.
I noticed that in
config/install/readonlymode.settings.ymlthe settings offorms.additionalare arrays, but when saving the module's settings they are strings.It can be fixed by overriding in
settings.phpwith the following (if no change is desired and the settings should be empty):Comment #9
helmo commentedI also ran into this while updating a site.
must be of the type array, string givenI commented the lines calling the _readonlymode_form_list_check() function to get through the
drush updbprocess.The second argument get's it's value from
$settings->get('forms.additional.view')so apparently that varies in type(#8).
Looking at the next line it uses preg_split which is a string function to process the argument. The functions comment section also describes the argument as 'A string of form id's separated by newlines.'
The last change to this line was in a 'Coder review and drupal-check changes.' commit which added the argument type. I think that if we just remove it we're back to a working state.
When an array is passed in anyway it generates a
PHP Warning: preg_split() expects parameter 2 to be string, array given(not fatal, but still not nice)The patch added here adds a check to avoid that warning.
Comment #10
Kojo Unsui commentedI've just applied #9 patch on 1.1 and it solves that bug. Thanks @Helmo !
Comment #11
srihari manepally commentedPatch #9 worked for me. Thanks.
Comment #12
berramou commentedI had the same error the Patch #9 fixed the fatal error for me.
but i had other errors after i applied it
When user don't have the "Access all forms while in Read Only Mode" permission and tried to access to content page (admin/content)
Comment #13
maskedjellybeanI can second what @berramou said. Since this is a less ugly error I'll use the patch, but it's not ready.
Comment #16
ambient.impactI ran into this error as well. Looking over the previous patches, they only address the symptom but not the root cause: that the configuration being saved isn't arrays of form IDs (as one would expect) but strings with new lines in them. I've opened a merge request that splits the fields into arrays before saving them to config, and also added an update hook to do the same thing for existing config.
Comment #17
ambient.impactComment #18
maskedjellybeanI tested MR 4 from @Ambient.Impact and found that I still see the same error. Here's what I did:
Comment #19
maskedjellybeanI'm sorry if this is frowned upon but I added a small commit to MR 4 to fix the error I described in my last comment. With that added I don't see any other errors.
It seems the way we are unsetting form elements may be overly aggressive and is the cause of
Warning: Undefined array key "show_view_elements". Wouldn't setting[#access] = FALSEbe safer? To be clear, this isn't a criticism of MR 4. The code I'm talking about already exists. See the foreach loop here at line 151 here: https://git.drupalcode.org/project/readonlymode/-/merge_requests/4/diffs...Comment #20
ambient.impactNot at all, issue forks are intended for this kind of collaboration so additional work is appreciated. It would be preferable to discuss additional changes beforehand however. In this case, I'm curious if you can replicate the the undefined array key warning using the dev branch (i.e. not this issue fork), and if so, then you should open a separate issue and create a new issue fork in that issue rather than in this one. On the other hand, if my merge request does indeed cause this warning, then it would be appropriate here.
Agreed that using
#accesswould likely be a lot safer and the better approach. Feel free to open a new issue and merge request with that change. 😉Comment #21
eric_a commentedWas this fixed in #3224538: Config schema errors? Or is it partially fixed?
The merge request here is all about arrays, while the other issue further stringified things.
Comment #22
eric_a commentedAnd more: #3354694: Argument 2 passed to _readonlymode_form_list_check() must be of the type array, string given
Comment #23
audioroger commentedUploading the patch generated from https://git.drupalcode.org/project/readonlymode/-/merge_requests/4/diffs... based on comment 19.
Don't be mad y'all, I know there are plenty of conversations around uploaded patches vs. using MR generated patches locally. For me, I'm contributing this patch to another project that doesn't have local patches, so I want a permanent link. So far as I can tell this is not yet supported in GitLab.
Comment #24
lmlima commentedPatch in #23 did not work for me on D10.
In admin/config/development/maintenance, I got:
TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in implode() (line 102 of modules/contrib/readonlymode/readonlymode.module).I could get a no error or warning install using
TypeError: Argument 2 passed to _readonlymode_form_list_check() must be of the type string, array given. Credit to OPTASYWarning: Undefined array key "show_view_elements". Credit to Ben TeegardenWarning: Undefined array key "actions"" in some administrative pages that I fixed appending the 'actions' key just like in item 2.Comment #25
lmlima commentedJust fixing filename from #24.
Comment #26
lmlima commentedComment #27
iheb.attia commentedSame patch as #24 but remove only 'show_view_elements' element from form.
Comment #28
altcom_neil commentedWe are using patch #23 successfully in production sites.
@Imlima If you were getting the
TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in implode()andTypeError: Argument 2 passed to _readonlymode_form_list_check() must be of the type string, array givenerrors after applying patch #23 then you hadn't rundrush updatedbto runreadonlymode_update_8002()which converts the 'forms.additional.edit' and 'forms.additional.view' config items into arrays? Or had they errored and failed somehow?There are now two ways of fixing the issue in patches, up to and including patch #23 and in the merge request it was all about making the two config vars arrays as the code was expecting, patch #25 and #27 are simpler by just changing what the code to expecting the strings as they are in the current config.
Personally I favour the first solution to make the config arrays as that is what the code uses in
_readonlymode_form_list_check(). If the config is saved as an array then it is only converted from string to array and back again once in the admin form. When it is being used during normal site operation the config is an array.By keeping it as a string in the config every time that
_readonlymode_form_list_check()is called the string has to be split into an array at that point. Not a massive overhead but it seems that it is better to store the config how it is intended to be used, not just as a consequence of how it is edited in the admin form?Comment #29
petermallett commentedAs mentioned in comment #21 above (#3115119-21: Fatal error due to saved additional form IDs being strings and not arrays),
it seems this patch may no longer be needed as the 1.3 release fixed the config schema by correctly specifying these values as strings rather than converting the storage to arrays: #3224538: Config schema errors.
It looks like upgrading to 1.3 , re-configuring the module, and re-exporting the config would fix things.edit: after looking at this more and discussing with affected users, I think we need to follow through with the idea in the previous comment (#28) and get the module updated so these values are treated properly as arrays at all times + db update if needed.
Comment #30
astonvictor commentedit's a duplicate of #3354694: Argument 2 passed to _readonlymode_form_list_check() must be of the type array, string given