- ๐ง๐ชBelgium rodrigo panchiniak fernandes
MR in #20 also fixes
Error: Cannot use a scalar value as an array in Drupal\Core\Render\Element\RenderElement::preRenderAjaxForm() (line 315 of /<redacted>/web/core/lib/Drupal/Core/Render/Element/RenderElement.php)
when adding a custom entity reference field (PHP 8.1, Drupal 10.0.8).
- First commit to issue fork.
- last update
almost 2 years ago 28,496 pass - Status changed to Needs review
over 1 year ago 12:03pm 26 May 2023 - ๐ท๐ดRomania vasike Ramnicu Valcea
- updated summary
- add related issueAlso drupal.org and api.drupal.org documentations should be updated.
- last update
over 1 year ago 29,401 pass - ๐บ๐ธUnited States smustgrave
Exactly same as MR. To run against 11.x
- Status changed to RTBC
over 1 year ago 7:18pm 26 May 2023 - ๐บ๐ธUnited States smustgrave
Passed 11.x also
Reviewing the changes seem fine. MAY need a test but will let committer decide.
- last update
over 1 year ago 29,401 pass - last update
over 1 year ago 29,402 pass - last update
over 1 year ago 29,402 pass - last update
over 1 year ago 29,411 pass - last update
over 1 year ago 29,417 pass 9:28 42:18 Running- last update
over 1 year ago 29,437 pass - last update
over 1 year ago 29,437 pass - last update
over 1 year ago 29,445 pass - last update
over 1 year ago 29,473 pass - last update
over 1 year ago 29,498 pass, 1 fail The last submitted patch, 29: 2651418-29.patch, failed testing. View results โ
- last update
over 1 year ago 29,499 pass - ๐ท๐ดRomania vasike Ramnicu Valcea
run re-test ... pass ... "revert the issue status"
- last update
over 1 year ago 29,505 pass - last update
over 1 year ago 29,551 pass - last update
over 1 year ago 29,553 pass - ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
Evaluating need for tests against https://www.drupal.org/project/drupal/issues/2972776#heuristics ๐ฑ [policy, no patch] Better scoping for bug fix test coverage RTBC (Which is not yet adopted, just as a thought exercise).
- Are there clear steps to reproduce on the issue?Yes
- Is it easy to verify via manual testing that the bug is fixed?Yes
- Is it a 'trivial' patch with small, easy to understand changes?Yes
- Is the code being changed in self-contained/@internal code that we don't expect contrib modules to interact with significantly? (plugins, controllers etc.)Yes
- In the case that the bug is committed with test coverage then later regresses, is the impact likely to be minimal or at least no worse than leaving the bug unfixed (for example site were unlikely to be actively mitigating the bug with workarounds/patches that would be removed when it's fixed)?Yes
- Is the bug fix achieved without adding new, untested, code paths?Yes
- To add test coverage, would it need an explicit 'regression' test that mainly prevents us reverting the patch rather than improving coverage in general?Yes
- If the test coverage was deferrred to a follow-up, would it be easy for someone who didn't work on the original bug report to pick it up?Yes
- Does the issue expose a general lack of test coverage for the specific subsystem, and if so would it be better to add generic test coverage for that subsystem in a separate issue so that the test coverage can be added in a maintainable way, rather than a regression test?Yes
So on that basis I think this is a good candidate for not adding tests, but I'll ask for second opinion
+++ b/core/lib/Drupal/Core/Render/Element/Ajax.php @@ -5,7 +5,21 @@ + * set to true to use default values.
nit I think this should be TRUE not true, can be fixed on commit
Moving to 10.1.x as 10.0.x is now security only
- last update
over 1 year ago 29,559 pass - last update
over 1 year ago 29,565 pass - last update
over 1 year ago 29,571 pass - Status changed to Needs work
over 1 year ago 7:09am 3 July 2023 - ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
+++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -268,6 +268,11 @@ public static function preRenderAjaxForm($element) { + // If set to TRUE, default values should be applied. + if ($element['#ajax'] === TRUE) { + $element['#ajax'] = []; + }
Is this actually needed?
We have instances of this in core in selection handlers, and they work - so I suspect not?
If they work without this change, this is just a docs issue and therefore we don't need tests
Crediting some others who helped me to review this
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 28,526 pass - Status changed to Needs review
over 1 year ago 10:02am 3 July 2023 - ๐ท๐ดRomania vasike Ramnicu Valcea
@larowlan as core introduces
'#ajax' => TRUE,
in several places for some elements
And as discussions on the issue and also on related issues say,
i would say we need to make sure it doesn't bring issues with it.I updated the MR adding just some small tests ... about element wit no ajax but also with no empty AJAX (
'#ajax' => TRUE,
)
And without this fix ... it will fail. - ๐ฌ๐งUnited Kingdom catch
On #33:
Is the code being changed in self-contained/@internal code that we don't expect contrib modules to interact with significantly? (plugins, controllers etc.)Yes
This should be a NO - the changes are in the render/AJAX system and the bug can be triggered by contrib usage of the API. Maybe we should re-word that one to make it more explicit?
To add test coverage, would it need an explicit 'regression' test that mainly prevents us reverting the patch rather than improving coverage in general?Yes
There is
RenderElementTest
so it might be a case of adding a method here, I'm not sure how straightforward that is though so probably a maybe? - Status changed to RTBC
over 1 year ago 5:38pm 14 July 2023 - ๐บ๐ธUnited States smustgrave
Can confirm #36 that without the fix the additional tests do fail.
Error : Cannot use a scalar value as an array
- last update
over 1 year ago 28,526 pass - last update
over 1 year ago 28,526 pass - last update
over 1 year ago 28,526 pass - last update
over 1 year ago 28,526 pass - last update
over 1 year ago 28,526 pass - Status changed to Needs work
over 1 year ago 10:22am 24 July 2023 - last update
over 1 year ago 28,526 pass - Status changed to Needs review
over 1 year ago 8:59am 20 November 2023 - ๐ง๐ชBelgium dieterholvoet Brussels
Moved the new docs to core.api.php.
- Status changed to Needs work
over 1 year ago 12:56pm 20 November 2023 - ๐บ๐ธUnited States smustgrave
Hiding patches if fix is going to be in MR.
MR needs to be updated to 11.x
- ๐ท๐ดRomania vasike Ramnicu Valcea
hmm ... this issue seems to be for 10.1.x ... not 11.x
but this still means we need to update the target branch .. so is there anyone with the permissions to update the target source
or i could create new MR(s) ... for 10.1.x and 11.x?
- Status changed to Needs review
over 1 year ago 8:09pm 20 November 2023 - Status changed to RTBC
over 1 year ago 1:22am 21 November 2023 - ๐บ๐ธUnited States smustgrave
Thanks! Happy to see that update the target branch didn't cause much issue, know sometimes it does.
Looking at the changes, the comments seem fine
Running test-only feature I get
There was 1 error: 1) Drupal\Tests\Core\Render\Element\RenderElementTest::testPreRenderAjaxForm Error: Cannot use a scalar value as an array /builds/issue/drupal-2651418/core/lib/Drupal/Core/Render/Element/RenderElement.php:322 /builds/issue/drupal-2651418/core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php:63 /builds/issue/drupal-2651418/vendor/phpunit/phpunit/src/Framework/TestResult.php:728 /builds/issue/drupal-2651418/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684 /builds/issue/drupal-2651418/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651 /builds/issue/drupal-2651418/vendor/phpunit/phpunit/src/TextUI/Command.php:144 /builds/issue/drupal-2651418/vendor/phpunit/phpunit/src/TextUI/Command.php:97 ERRORS!
Think this is good
54:28 49:32 Running- last update
over 1 year ago 30,605 pass, 2 fail - last update
about 1 year ago 30,667 pass, 2 fail - last update
about 1 year ago 30,674 pass, 2 fail - last update
about 1 year ago 30,683 pass, 2 fail - last update
about 1 year ago 30,685 pass, 2 fail - last update
about 1 year ago 30,687 pass, 2 fail - last update
about 1 year ago 30,687 pass, 2 fail - last update
about 1 year ago 30,695 pass, 2 fail - last update
about 1 year ago 30,697 pass, 2 fail - last update
about 1 year ago 30,705 pass, 2 fail - last update
about 1 year ago 30,711 pass, 2 fail - last update
about 1 year ago 30,763 pass, 2 fail - last update
about 1 year ago 30,765 pass, 2 fail - last update
about 1 year ago 25,895 pass, 1,805 fail - Status changed to Needs work
about 1 year ago 7:48pm 20 December 2023 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
So the reason
['#ajax'] = TRUE
works in the entity reference items is because it has special code that changes it into an array. It is not meaning to change it to default values at all :)See \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsAjaxProcessElement() for where this happens. If this did not occur then treating TRUE like an array would produce errors on PHP 8.1.
I think we could consider not making this change but instead documenting the places in the entity reference system where #ajax is being set to TRUE with an
@see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsAjaxProcessElement()
- Status changed to Needs review
about 1 year ago 9:44am 29 January 2024 - ๐ท๐ดRomania vasike Ramnicu Valcea
@alexpott this is not related with
\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem
But "others" as
\Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
(Maybe also with)\Drupal\user\Plugin\EntityReferenceSelection\UserSelection
Details about the issue/errors are in the comments and also related issue
Also updated the issue info.Could you please check/review again?
Thanks - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
@vasike I promise you this has everything to do with EntityReferenceItem::fieldSettingsAjaxProcessElement().
The Plugin\EntityReferenceSelection\DefaultSelection::buildConfigurationForm() and Plugin\EntityReferenceSelection\UserSelection::buildConfigurationForm() are called by \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsForm() - specifically from the line:
$form['handler']['handler_settings'] += $handler->buildConfigurationForm([], $form_state);
The ::fieldSettingsForm() method is the one that adds
'#process' => [[static::class, 'fieldSettingsAjaxProcess']],
too... which results in$element['#ajax'] = TRUE;
being converted to
$element['#ajax'] = [ 'trigger_as' => ['name' => 'handler_settings_submit'], 'wrapper' => 'field-combined', 'element' => $main_form['#array_parents'], ];
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
This
#ajax => TRUE
is just a shorthand for Entity selection handlers - so that they can get the correct[โ#ajaxโ][โelementโ]
set without having to repeat the#process
logic everywhere. - Status changed to Needs work
about 1 year ago 12:40am 2 February 2024 - ๐บ๐ธUnited States smustgrave
Thanks a ton @alexpott for taking a look!
- Merge request !6458Issue #2651418 by vasike, DieterHolvoet, smustgrave, rpayanm, quietone, lauriii: Non-array values for #ajax - make them array. โ (Closed) created by vasike
- Status changed to Needs review
about 1 year ago 4:15pm 5 February 2024 - ๐ท๐ดRomania vasike Ramnicu Valcea
New MR https://git.drupalcode.org/project/drupal/-/merge_requests/6458
and new approach - make sure we have an array for#ajax
element property ... get rid of'#ajax' => TRUE
And it seems it works (All Green)
Also checked with the related issue MR ... and we don't get the errors.What do you think @alexpott?
And of course thank you.
- ๐บ๐ธUnited States smustgrave
smustgrave โ changed the visibility of the branch 11.x to hidden.
- ๐บ๐ธUnited States smustgrave
smustgrave โ changed the visibility of the branch 2651418-non-array-values-for to hidden.
- Status changed to Needs work
about 1 year ago 8:00pm 16 February 2024 - ๐บ๐ธUnited States smustgrave
Possible to get a test for the new approach?
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
The current approach would be a BC break since before a value of FALSE would not add ajax but now it would. Also a value of TRUE would be not add the ajax default so custom and contrib would be broken.
I don't think it is worth changing the behaviour here. I think it is worth added @see's to where #ajax is being set to TRUE so we don't wonder the whys and wherefores in the future.
- Status changed to Needs review
about 1 year ago 11:00am 21 February 2024 - ๐ท๐ดRomania vasike Ramnicu Valcea
ok. there could BC breaks
small update forTRUE
cases.imho, there could a change records to invite custom devs and contrib maintainers to use
[]
instead ofTRUE
.
To avoid some cases as described in the issue and the "use case" from related issue. - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
@vasike I do not understand why we want to change this. We can add the @see's so people are not confused in the future and be done.
- ๐ท๐ดRomania vasike Ramnicu Valcea
@alexpott thanks a lot for your persistence: I was blind, but not ... I can see
Sorry I didn't listen ... I was blinded by the "edge case" in Views Modal ... which it doesn't work ("properly") with form validation or ajax ... but this is another story/issue (Drupal chapter).So, for now 2 updates:
1. new "documentation" MR
2. Update the related issue MR ... removing the ajax, as we did for#required
property
within this commit https://git.drupalcode.org/project/drupal/-/merge_requests/4053/diffs?co...How are we ... now?
p.s. Maybe in another places, this could work
$form['#process'][] = [EntityReferenceItem::class, 'fieldSettingsAjaxProcess'];
But do we need to mention ... somewhere? - ๐ท๐ดRomania vasike Ramnicu Valcea
vasike โ changed the visibility of the branch 2651418-ajax-array-only to hidden.
- Status changed to Needs work
11 months ago 6:34pm 26 March 2024 - ๐บ๐ธUnited States smustgrave
Thanks @alexpott for taking another look.
- Status changed to Needs review
11 months ago 7:29pm 26 March 2024 - Status changed to Needs work
11 months ago 1:58pm 27 March 2024 - ๐บ๐ธUnited States smustgrave
Believe the feedback from @alexpott has been addressed here but left 1 comment about one of the comments.
- Status changed to Needs review
11 months ago 2:30pm 27 March 2024 - ๐ท๐ดRomania vasike Ramnicu Valcea
indeed ... missed to include the change in the previous commit
- Status changed to RTBC
11 months ago 3:02pm 27 March 2024 - Status changed to Fixed
11 months ago 3:45pm 27 March 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
Backported to 10.2.x as this is a docs fix.
Committed and pushed fe3aa496f7 to 11.x and 2404bcd91a to 10.3.x and b825f8e2e5 to 10.2.x. Thanks!
For those like @DieterHolvoet who experience bugs due to this - it must be happening because your render array contains an unprocessed form. Forms must be processed before the prerender is called so toy need to track down why that is occurring.
-
alexpott โ
committed b825f8e2 on 10.2.x
Issue #2651418 by vasike, DieterHolvoet, smustgrave, Xano, rpayanm,...
-
alexpott โ
committed b825f8e2 on 10.2.x
-
alexpott โ
committed 2404bcd9 on 10.3.x
Issue #2651418 by vasike, DieterHolvoet, smustgrave, Xano, rpayanm,...
-
alexpott โ
committed 2404bcd9 on 10.3.x
-
alexpott โ
committed fe3aa496 on 11.x
Issue #2651418 by vasike, DieterHolvoet, smustgrave, Xano, rpayanm,...
-
alexpott โ
committed fe3aa496 on 11.x
Automatically closed - issue fixed for 2 weeks with no activity.