Warning: Undefined array key "#markup" in Drupal\Core\Render\RenderCache->getCacheableRenderArray()

Created on 1 December 2023, 12 months ago
Updated 27 December 2023, 11 months ago

API page: https://api.drupal.org/api/drupal/core%21modules%21block%21block.api.php...

<?php
function custom_module_block_access(Block $block, $operation, AccountInterface $account) {
  if ($block->id() == 'blocktodisplay' && $operation == 'view') {
    return AccessResult::forbiddenIf(TRUE)->addCacheableDependency($block);
  }
}
?>

Enter a descriptive title (above) relating to function hook_block_access, then describe the problem you have found:

Warning: Undefined array key "#markup" in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 333 of D:\xampp\htdocs\project\docroot\core\lib\Drupal\Core\Render\RenderCache.php)

💬 Support request
Status

Postponed: needs info

Version

10.1

Component
Render 

Last updated 3 days ago

Created by

🇮🇳India shrikant.dhotre

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

Comments & Activities

  • Issue created by @shrikant.dhotre
  • Status changed to Postponed: needs info 12 months ago
  • With apologies, I do not understand the meaning of this issue. What is a "PFB"?

  • 🇮🇳India shrikant.dhotre

    I have removed PFB,
    I am getting warning which I am adding block on login page.

  • Status changed to Active 11 months ago
  • Status changed to Postponed: needs info 11 months ago
  • This needs more information. I asked you a question but you did not answer it. Get a stack trace.

  • Status changed to Needs work 11 months ago
  • 🇮🇳India shrikant.dhotre

    Hi @cilefen,

    I am using this hook one of my module and it giving me below error

    Warning: Undefined array key "#markup" in Drupal\Core\Render\RenderCache->getCacheableRenderArray() (line 333 of D:\xampp\htdocs\project\docroot\core\lib\Drupal\Core\Render\RenderCache.php)

    Inside this hook, I am calling a block which created bin OpenID module. which need to be display in custom login page.

    I am getting this warning. Need help to resolve the warning

  • 🇮🇳India prashant.c Dharamshala

    @shrikant.dhotre

    Could you please provide the complete steps to reproduce the issue?

    Thanks

  • Status changed to Postponed: needs info 11 months ago
  • Status changed to Needs review 11 months ago
  • 🇮🇳India shrikant.dhotre

    Hi @Prashan.c,
    I have implement below code.

    /**
     * Implements hook_block_access().
     *
     * Hide Open ID connect block if Drupal Login form is enabled.
     */
    function custom_module_block_access(Block $block, $operation, AccountInterface $account) {
      $drupalLogin = \Drupal::state()->get('drupal_login_active');
      if ($drupalLogin && $block->id() == 'openidconnectlogin_3' && $operation == 'view') {
        return AccessResult::forbiddenIf(TRUE)->addCacheableDependency($block);
      }
    }
    
  • Status changed to Postponed: needs info 11 months ago
  • 🇺🇸United States smustgrave

    Instead of id() would check the pluginId.

    Instead of forbiddenIf would just use Forbidden since TRUE isn't a condition.

    Also may have to dig into the logs some more to see what is calling markup.

  • 🇨🇦Canada arakwar

    I got the same issue while trying to limit logins to my main "Domain Access" domain name.

    The code we're trying to implement :

    /**
     * Implements hook_form_alter().
     */
    function domain_login_disable_form_alter(&$form, &$form_state, $form_id) {
      if ($form_id == 'user_login_form') {
        /** @var \Drupal\domain\Entity\Domain $active */
        $active = \Drupal::service('domain.negotiator')->getActiveDomain();
    
        if (is_null($active)) {
          $active = \Drupal::entityTypeManager()->getStorage('domain')->loadDefaultDomain();
        }
    
        if (is_null($active)) {
          // If there's an issue with domain, we won't block the login form.
          return;
        }
    
        if (!$active->isDefault()) {
          $form['#access'] = FALSE;
        }
      }
    }
    

    When going trough a page request with Xdebug, we can see that in core/lib/Drupal/Core/Render/RenderCache.php, in the getCacheableRenderArray() function, the $elements array doesn't have a #markup element.

    Adding $form['#markup'] = NULL; in our function right after we set #access to FALSE fix the issue.

    Is it an intended behavior?

  • 🇪🇸Spain leandro713 🇪🇸 Madrid 🤠

    I am having this problem too on a fresh new installation of Drupal 10, the error prevents the rendering of the new user creation form. It only appears there.

Production build 0.71.5 2024