Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kwiechmann opened this issue Nov 3, 2023 · 0 comments
Open

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

kwiechmann opened this issue Nov 3, 2023 · 0 comments
Labels

Comments

@kwiechmann
Copy link

kwiechmann commented Nov 3, 2023

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++;
    }
@Kingdutch Kingdutch added the 3.x label Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants