Problem/Motivation

When try to make a donation receive
"Drupal\Core\Security\UntrustedCallbackException: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was field_group_form_pre_render. See https://www.drupal.org/node/2966725 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 96 of core\lib\Drupal\Core\Security\DoTrustedCallbackTrait.php). "

Steps to reproduce

In use:
"drupal/core-recommended": "^9.2",
"drupal/field_group": "3.2",
"drupal/commerce_donation_flow": "^1.0@beta"

Configure everything like in instruction:https://www.drupal.org/project/commerce_donation_flow

Go to http://site.local/donate/ after redirect to http://site.local/donate/25/donation and got:

"Drupal\Core\Security\UntrustedCallbackException: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was field_group_form_pre_render. See https://www.drupal.org/node/2966725 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 96 of core\lib\Drupal\Core\Security\DoTrustedCallbackTrait.php). "

Proposed resolution

Change passing prerender function.

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

namli created an issue. See original summary.

mrweiner’s picture

StatusFileSize
new1.42 KB

I'm not sure that the correct method is being called in the MR.

  1. Right now, the pane is calling field_group_form_pre_render()
  2. field_group_form_pre_render() calls field_group_form_process()
  3. field_group_form_process() calls FormatterHelper::formProcess()

As such, attached patch calls fromProcess() instead of entityViewPrender().

mrweiner’s picture

Status: Active » Needs review
mrweiner’s picture

Actually my last patch errors out due to some pass by reference error. There's a related problem being worked on in https://www.drupal.org/project/field_group/issues/2894213. I don't know if we can actually use the same pre_render implementation as before until a TrustedCallback exists to replicate the behavior. entityViewPrender may be the best bet for now, not sure

mrweiner’s picture

Scratch that -- I think patch #4 is the correct approach. There's a patch in field_group that addresses the problem:https://www.drupal.org/files/issues/2021-06-11/3218305-formprocess-shoul...

Unfortunately that just means that people need to apply that patch for this one to work correctly.

frankdesign’s picture

Thanks for the advice @mrweiner. Patch at #3 above along with patch #2 at https://www.drupal.org/project/field_group/issues/3218305 solved the issue for me.

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

fathershawn’s picture

This needs manual testing because of the upstream issue. Test passes on my local (with Commerce deprecation notices) with the field_group patch in place.

Added Field Group as an explicit requirement. Be sure to use v3.2

Anyone using composer patches can add the following in their composer.json

In the "extra" section of your composer.json

 "patches": {
          "drupal/field_group": {
              "issue-3218305: pass by reference": "https://www.drupal.org/files/issues/2021-06-11/3218305-formprocess-should-be-not-reference.patch"
          }
      }
fathershawn’s picture

Manually verified on a fresh D9 install

  • FatherShawn committed de2542d on 1.0.x authored by namli
    Issue #3231024 by namli, mrweiner, FatherShawn: Render #pre_render...
fathershawn’s picture

Status: Needs review » Fixed
fathershawn’s picture

Status: Fixed » Needs work

Re-opening. I missed that we test for field_group being present. It should not be a requirement

fathershawn’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.