Issue with doTrustedCallback() must be callable, array given

Created on 21 July 2021, over 3 years ago
Updated 12 June 2024, 5 months ago

Various autoloading problems seem to cause this error

TypeError: Argument 1 passed to Drupal\Core\Render\Renderer::doTrustedCallback() must be callable, array given, called in /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php on line 781 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 51 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php)."</strong>

To find out more information on the cause on your particular site try the patch in #42 or the technique described in #27

Remaining Tasks

Figure out the best way to report a more helpful error message than the mostly useless that people are currently getting and create an MR for that.

💬 Support request
Status

Postponed: needs info

Version

11.0 🔥

Component
Render 

Last updated 3 days ago

Created by

🇮🇳India sardiwal

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I was also getting this same error after following the subtheme Olivero instructions.

    https://github.com/mherchel/olivero-subtheme

    What happened was I was renaming everything to olivero_company. Even though I told PHPStorm to use case sensitive when performing the find/replace, it still performed the action twice on class OliveroPreRender implements TrustedCallbackInterface {} making it class Olivero_company_companyPreRender implements TrustedCallbackInterface {}.

    It might be worth checking the above class declaration in the src/OliveroPreRender.php file. Remember, this may be named differently depending on your theme name.

  • 🇦🇺Australia imclean Tasmania

    To find the find the problem code, edit core/lib/Drupal/Core/Render/Renderer.php and add the debug code to the end of the function doCallback() immediately before return $this->doTrustedCallback().

    For example, if you're using devel/kint:

      kint($callback);
    

    If the error is resulting in a WSOD then the last one displayed will tell you where the problem lies.

    In my case, I forgot to make one of the callbacks a static function.

  • 🇺🇸United States tjtj

    I get this error just after I upgrade from D9 to D10.0.5

    TypeError: Drupal\Core\Render\Renderer::doTrustedCallback(): Argument #1 ($callback) must be of type callable, array given, called in /srv/www/htdocs/ssl2/www/web/core/lib/Drupal/Core/Render/Renderer.php on line 788 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 51 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php).

    I wrote nonie of the code.

  • 🇦🇺Australia imclean Tasmania

    You may also need a use statement in your module file.

    e.g. my_module.module:

    use Drupal\my_module\MyModuleCallback;
    
    /*
     * Implements hook_block_view_alter().
     */
    function my_module_block_view_alter(array &$build, BlockPluginInterface $block) {
      if ($build['#plugin_id'] === 'block_my_block') {
        $build['#pre_render'][] = [MyModuleCallback::class, 'preRender'];
      }
    }

    There are quite a few issues which all result in the same error message.

  • 🇦🇹Austria ballaboidi

    I get the same Error as the #21, it seems to have something to do with the "Claro" Theme and the { [0]=> string(33) "Drupal\Core\Render\Element\Hidden" [1]=> string(15) "preRenderHidden" } component.

    After this component is loaded, the error occurs.

    The same instance with the Stark 10.0.9 theme works as expected.

    If anyone could look into this it would be highly appreciated, my server setup:

    Linux CentOS
    PHP8.1 & PHP 8.2 both failed
    MariaDB 10.5.19

  • I had the same problem cloning Olivero. There was a mismatch in the naming of the PreRender class. Sounds like you may have run into the same problem cloning Claro.

    https://github.com/mherchel/olivero-subtheme/issues/1#issuecomment-16052...

  • 🇺🇸United States jnimchuk

    I have the same issue.

    I used the Stark theme for both Admin and Website and it still gave me this error:

    ===============
    TypeError: Drupal\Core\Render\Renderer::doTrustedCallback(): Argument #1 ($callback) must be of type callable, array given, called in /var/www/vhosts/thejdngroup.com/domains/test10.portrevolt.com/core/lib/Drupal/Core/Render/Renderer.php on line 788 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 57 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php).
    ===============

    Hope someone can resolve this soon ...

  • Status changed to Postponed: needs info over 1 year ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Hi folks

    For everyone posting here, it would be really great if you could dig into this a bit more and provide an example of the array being passed that Drupal can't execute.

    As mentioned above it sounds like an issue with autoloading, so could be related to how we register theme namespaces in the autoloader.

    Lee

  • 🇺🇸United States TolstoyDotCom L.A.

    Have those who have this problem used composer to install the site and are there any issues with the vendor directory?

  • 🇵🇱Poland azovsky

    drush cr -y fixed the ...TypeError: Argument 1 passed to Drupal\Core\Render\Renderer::doTrustedCallback() must be callable, array given... issue for me.

  • 🇮🇳India santhosh@21

    When I upgrade from 9.5.1 to Drupal 10.1 I am getting the same error only in my AWS hosting and not in my local site

    "[Mon, 09/11/2023 - 12:04] [Error] [php] [client: 10.80.35.171, Anonymous] TypeError: Drupal\Core\Render\Renderer::doTrustedCallback(): Argument #1 ($callback) must be of type callable, array given, called in /opt/drupal/web/web/core/lib/Drupal/Core/Render/Renderer.php on line 788 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 57 of /opt/drupal/web/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php)."

    I have enabled the default olivero theme but still its giving the same issue.
    Someone please suggest solution if you have anything.

  • 🇮🇳India santhosh@21

    drush cr -y fixed the issue for "Drupal\Core\Render\Renderer::doTrustedCallback()"

  • 🇪🇸Spain lapurddrupal

    After install recommended project with composer I have the same error upgrading from 9.5 to 10.1.3 PHP 8.1.12. Patch 3224723-10 failed.
    I am stuck now and will not migrate the productive system to 10.

  • 🇺🇸United States TolstoyDotCom L.A.

    The patches in #10 & #11 probably won't work.

    I posted a link to things you can do in #27.

    It'd be great if someone who's experiencing this issue would spend a little time trying to find out what's in the callback.

  • 🇧🇪Belgium flyke

    Had the same error after updating to Drupal 9.5.11 but also updating Gin theme.
    When I applied patch from #11, then the error changed into:
    Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Toolbar::localTasks. See https://www.drupal.org/node/2966725
    I am now investigating the gin_toolbar module as possible culprit.

  • 🇧🇪Belgium flyke

    I needed to get a website that was offline due to this error back online asap.
    The fastest method was putting these lines in comment in web/modules/contrib/gin_toolbar/gin_toolbar.module.

  • 🇺🇸United States codesmith San Francisco

    This just happened to me updating a site from Drupal 9.5 to Drupal 10. The site uses the Claro theme for both front and back end. Drush not working and only getting the WSOD. From #27 above I did the second part of this comment and was able to get a bootstrap. Then clearing the cache fixed the issue.

    https://www.drupal.org/forum/support/upgrading-drupal/2023-05-30/migrati...

  • 🇫🇮Finland lauriii Finland

    I ran into this as well while updating to Drupal 9.5.

    I was able to debug this by adding this before the call to \Drupal\Core\Security\DoTrustedCallbackTrait::doTrustedCallback and inspecting what is the value of $callback when it's not a callable:

    if (!is_callable($callback)) {
      xdebug_break();
    }
    

    For some reason it was caused by Gin Toolbar having a pre_render calling ::localTasks on an undefined class; Toolbar. I removed Gin Toolbar from the code base and installed composer dependencies again and for some reason it fixed the problem. It also looks like the code was different even though the version of the module remained same 🤔 I tried to check the history for that module but didn't find any clues to why this was happening.

    The reason why others are running into this is probably something else since the problem I ran into seems quite arbitrary. I hope the steps for debugging this at least helps.

  • 🇺🇸United States chefigueroa Baltimore, MD

    I had the same error that was only on the production environment. I ran drush cr and it fixed it.

  • 🇫🇷France mupsi

    I had the same error after upgrading from 9.5.11 to 10.1.7, only on my staging environment (Platform.sh). Like for chefigueroa, a simple drush cr fixed it for me. Hope that helps.

  • 🇩🇪Germany ikke

    Maybe this helps:
    Before a Olivero subtheme was finally displayed as desired not only under Drupal 9, but also under Drupal 10, only one thing was missing.

    Let's say the copied Olivero subtheme is called "coco".

    In /themes/custom/coco/src/, OliveroPreRender.php then becomes CocoPreRender.php (even if the theme itself actually starts with a lowercase letter, the file name of this file must start with an uppercase letter).

    The file still contains the following in line 12...
    class OliveroPreRender implements TrustedCallbackInterface {
    ...then...
    class CocoPreRender implements TrustedCallbackInterface {
    .

    And now back up to line 3, where it becomes (and I haven't read this anywhere else)...
    namespace Drupal\olivero;
    ...then...
    namespace Drupal\coco;

    Now into the file coco.theme:
    Line 8
    use Drupal\coco\CocoPreRender;
    Line 550
    $info['text_format']['#pre_render'][] = [CocoPreRender::class,
    line 555
    $info['status_messages']['#pre_render'][] = [CocoPreRender::class,

    I created the original working version of my Olivero subthemes for Drupal 8+9 with the help of
    https://github.com/mherchel/olivero-subtheme
    . I had to make the additional changes described above so that it also runs under Drupal 10.

  • 🇨🇦Canada dalin Guelph, 🇨🇦, 🌍

    I ran into this but it was only happening on the live site (Pantheon, but I don't think that matters). If I cleared the cache, some of the domains worked but not others. If I cleared the cache again, then a different set of domains started working. I attempted to deploy the attached patch to get more info. But simply the act of deploying seemed to kick it into gear and it started working for all domains.

  • 🇺🇸United States TolstoyDotCom L.A.

    Not to belabor the point, but #8, #26, & #27 all have ways you can help debug what's actually going on. Please take out a few minutes to do one of those.

  • 🇨🇦Canada dalin Guelph, 🇨🇦, 🌍
Production build 0.71.5 2024