Problem/Motivation
I got warning on node form where I use field groups in paragraphs.
Warning: Parameter 1 to Drupal\field_group\FormatterHelper::formProcess() expected to be a reference, value given in Drupal\Core\Render\Renderer->doTrustedCallback() (line 101 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php).
Steps to reproduce
1. Create paragraph type
2. Create some fields and add some field groups on manage form display
3. Create content type and add paragraph field
4. Open node add page
5. Warning will be displayed
Proposed resolution
As in Drupal Core all render callbacks have value arguments (not reference) we should remove '&' symbol from public static function formProcess(array &$element, FormStateInterface $form_state = NULL, array &$form = []);
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3218305-formprocess-should-be-not-reference-10.patch | 576 bytes | dxvargas |
| #2 | 3218305-formprocess-should-be-not-reference.patch | 649 bytes | Andrii Kleba |
Comments
Comment #2
Andrii Kleba commentedI have the same problem.
This path fixed it.
Comment #3
swentel commentedTriggering tests
Comment #4
swentel commentedNote, probably a duplicate of #3147495: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface
Comment #5
mrweiner commentedThis isn't really a duplicate of #3147495: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface, although the patch is needed for other developers to properly address the error noted in that issue.
Comment #6
mrweiner commentedUpdating status. This fixes the problem for me.
Comment #7
frankdesign commentedPatch at #2 solved the issue for me. Thanks
Comment #8
nils.destoop commentedI agree with the patch. But if you look at Drupal core, all process functions are receiving it by reference. I don't know the reason, as you are expected to return the element.
If you look in formBuilder, you'll see that it's called by reference. I think cause of this warning is idd triggered by #3147495, as that one is the paragraph implementation instead of the processing handling in drupal core form builder.
Comment #9
damienmckennaClarifying the title; no bunnies were harmed ;-)
Comment #10
dxvargas commentedI've updated the patch since it was failing to apply to current dev version (8.x-3.x).
Comment #11
dxvargas commentedTests are failing just like they are failing in https://www.drupal.org/project/field_group/issues/2894351#comment-14394498.
The changes I've made are minimal, the tests are failing because of external problems. I hope the issue can go back to RTBC soon!
I put the issue in "Needs Review", please check!
Comment #12
dxvargas commentedComment #13
donquixote commentedWhy is this used as a '#pre_render' callback?
It is only meant to be used as form '#process'.
Could there be a 3rd party module that uses the callback with '#pre_render'?
Comment #14
mrweiner commented#10/#11 looks good to me.
@donquixote see https://www.drupal.org/project/field_group/issues/3147495#comment-14214001 for the #pre_render stuff. third-party modules need to update their implementations if they are seeing the noted error.
Comment #15
berdirOn the preprocess/pre_render discussion, this was changed in field_group at some point as a new function that replaced the previous pre_render. See this commit in paragraphs:
And then the process function was converted to a safe callback as part of the D9 update, and if you get this error then I assume that's because contrib or custom modules made it through those two API changes incorrectly.
As #8 said, #process is actually called with a reference, I don't know why either, it has been like this for at least 12 years (
$element = $process($element, $form_state, $form_state['complete form']);in D7, which just happens to support that and there is no explanation that I can find and D8 changed to syntax and kept that).Since it's not needed it's fine to change it but the only reason to so is to be kind to invalid integrations that did not do the #pre_render => #process switch. I assume there is a reason that this change happened and not calling it correctly might result in other problems? And it's definitely not a major bug. Leaving up to the maintainers to commit or close as won't fix.
(I was asked to provide feedback here about this)
Comment #16
swentel commentedOk, closing then, thanks for the clarification!