Problem/Motivation
When I am trying to save 'access unpublished' setting form (/admin/config/content/access_unpublished) , I am getting below error
TypeError: Drupal\Core\Render\Element::children(): Argument #1 ($elements) must be of type array, null given, called in /docroot/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php on line 361 in Drupal\Core\Render\Element::children() (line 72 of /docroot/core/lib/Drupal/Core/Render/Element.php).
Steps to reproduce
1. Download access_unpublished module (composer require 'drupal/access_unpublished:^1.5')
2. Install/enable access_unpublished
3. Navigate to access unpublished setting form /admin/config/content/access_unpublished
4. Click on "Save configuration"
Drupal Version - 10.2.3
Php version - 8.1
I replicate this issue on https://simplytest.me/ as well.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | access_unpublished-3421309-27-MR32.patch | 6.71 KB | mably |
| #14 | interdiff_12-14.txt | 4.4 KB | jakaeser |
| #14 | access_unpublished-n3421309-14.patch | 4.23 KB | jakaeser |
| #13 | interdiff_7-12.txt | 664 bytes | jakaeser |
| #13 | access_unpublished-n3421309-12.patch | 957 bytes | jakaeser |
Issue fork access_unpublished-3421309
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
Comment #2
Sana.Neyazi commentedComment #3
Sana.Neyazi commentedThis issue is only happening with Drupal core 10.2 and it is working fine with Drupal 10.0, do we have any patch for this issue?
Comment #4
sourabhjainI am able to replicate the issue.
Let me try to work on this.
Comment #5
damienmckennaComment #7
damienmckennaThe problem is the validation on the modify_http_headers field, if that's removed the form can save correctly.
This patch is a bandaid that lets the settings form save, but it needs a proper fix that uses the correct validation logic.
Comment #8
capellicThank you @DamienMcKenna for this patch and all that you do! The patch works for me!
Comment #9
sourabhjainComment #10
gun_dose commentedThe reason of this error is that module settings form uses ListItemBase::validateAllowedValues method as validation callback. But at the last versions of Drupal allowed values form of list fields was totally refactored. See this core commit https://git.drupalcode.org/project/drupal/-/commit/693ced9cd830f9b1d0942...
So to fix thie we need to either refactor module settings form to use the same approach as list fileds or copy the old validation callback to SettingsForm class. Unfortunately I can't do this because on my current froject we don't use headers settings, and in my case patch from #7 solved my problem
Comment #11
johnpicozziI can confirm the patch from #7 resolves the issue, but we will need a long term fix to add the validation correctly. Going to get this issue some attention as this module was a module of the week on Talking Drupal. Thanks All!
Comment #13
jakaeser commentedAfter applying the patch from #7, I received this error on the settings page:
Warning: foreach() argument must be of type array|object, string given in Drupal\access_unpublished\Form\SettingsForm->prepareHeadersDisplay() (line 127...Still not a long-term fix, but here's an updated patch to prevent that from happening.
Comment #14
jakaeser commentedIt didn't take long to realize my previous patch isn't quite going to cut it. Changing the expected value of the field from an array to a string unsurprisingly has some negative side-effects. Here's a patch that copies over the previous form validation from ListItemBase. It should be a good bit more robust and allow you to actually use the modify_http_headers setting.
I don't think this is an ideal long-term fix, either. The best path forward, in my humble opinion, is to match what core did in https://www.drupal.org/project/drupal/issues/2521800.
Comment #15
kopeboypatch #14 does remove the error and allowed me to save the form, but I'm not sure it makes the headers setting work: I couldn't find the one I had set in the Response headers from the Chrome inspector's Network tab.
Comment #16
rajab natshahComment #17
rajab natshahComment #18
chr.fritschComment #20
ushma commentedhi chr.fritsch, I have opened MR for the fix. Please review.
Comment #21
jaydarnellPatch #14 doesn't seem to work for Drupal 11.2.1
Comment #22
darby3Patch #14 seems to work for my needs (Drupal 11.2.4).
Comment #23
alphex commentedCan confirm, patch in comment #14 fixes the problem for Drupal 10.5.x
Comment #26
mably commentedComment #27
mably commentedAdded a patch corresponding to the new MR 32. Tested successfully on Drupal 11.2.8.
Comment #28
generalredneckWhen following the steps to reproduce on a clean install, I receive the following errors.
Warning message
Schema errors for access_unpublished.settings with the following errors: access_unpublished.settings:modify_http_headers variable type is string but applied schema class is Drupal\Core\Config\Schema\Sequence. These errors mean there is configuration that does not comply with its schema. This is not a fatal error, but it is recommended to fix these issues. For more information on configuration schemas, check out the documentation.
Error message
Warning: foreach() argument must be of type array|object, string given in Drupal\access_unpublished\Form\SettingsForm->prepareHeadersDisplay() (line 204 of modules/contrib/access_unpublished/src/Form/SettingsForm.php).
Drupal\access_unpublished\Form\SettingsForm->prepareHeadersDisplay() (Line: 76)
Drupal\access_unpublished\Form\SettingsForm->buildForm()
call_user_func_array() (Line: 528)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 279)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Comment #29
mably commentedNice catch @generalredneck!
The warnings should have disappeared now.
Added an empty-headers test case to ensure no warnings are triggered.
Comment #31
generalredneckLets call this toddler aged issue fixed. Thank you Mably for lighting the fire... and thank you to the rest of you for testing and patching and putting forth the hard work. This is availible in the dev version for the immediate future.