Skip to content

Invalid render array key in Drupal\Core\Render\Element::children #1373

@kwiechmann

Description

@kwiechmann

The following error messages appear in dblog:

  • User error: "cache" is an invalid render array key in Drupal\Core\Render\Element::children() (line 103 of C:\xampp\htdocs\cia-drupal\docroot\core\lib\Drupal\Core\Render\Element.php)
  • User error: "view" is an invalid render array key in Drupal\Core\Render\Element::children() (line 103 of C:\xampp\htdocs\cia-drupal\docroot\core\lib\Drupal\Core\Render\Element.php)

Findings: Error is generated because is not of type array.

  • when $key = "cache", $value is of type Drupal\Core\Cache\CacheableMetaData
  • when $key = "view", $value is of type Drupal\views\ViewExecutable

Issue confirmed in environments:
#1

  • PHP 8.2
  • Drupal Core 10.1.4
  • graphql 8.x-3.3
  • graphql_views 8.x-1.1

#2

  • PHP 8.1.22
  • Drupal Core 10.1.2
  • graphql 8.x-3.1
  • graphql_views 8.x-1.1

Steps to reproduce:

  • Create a view
  • Add display of type graphql output
  • Reload view page with the graphql display selected or stay on page and click the "Update preview" button.

Consider:

  • Determine why $value is still an object instead of a render array
  • Patch core's Element.php which does not to cause any ill effects
    foreach ($elements as $key => $value) {
      if (is_int($key) || $key === '' || $key[0] !== '#') {
        if (is_array($value)) {
          if (isset($value['#weight'])) {
            $weight = $value['#weight'];
            $sortable = TRUE;
          }
          else {
            $weight = 0;
          }
          // Supports weight with up to three digit precision and conserve
          // the insertion order.
          $child_weights[$key] = floor($weight * 1000) + $i / $count;
        }
        // Only trigger an error if the value is not null.
        // @see https://www.drupal.org/node/1283892
        // 
        // PATCHING CORE: !is_object check here.
        // 
        elseif (isset($value) && !is_object($value)) {
          trigger_error(new FormattableMarkup('"@key" is an invalid render array key', ['@key' => $key]), E_USER_ERROR);
        }
      }
      $i++;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions