Score:0

User error : "2" is an invalid render array key dans Drupal\Core\Render\Element::children()

jp flag

I face off this message on certains pages, somtimes relate to twig template part, sometimes to other things. In watchdog:

    User error : "2" is an invalid render array key dans Drupal\Core\Render\Element::children() (/home//www/pfdev/multid9/recommended-project/web/core/lib/Drupal/Core/Render/Element.php ligne 98)
#0 /home//www/pfdev/multid9/recommended-project/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(256, '"2" is an inval...', '/home/provencef...', 98)
#1 [internal function]: _drupal_error_handler(256, '"2" is an inval...', '/home/provencef...', 98)
#2 /home//www/pfdev/multid9/recommended-project/web/core/lib/Drupal/Core/Render/Element.php(98): trigger_error('"2" is an inval...', 256)
#3 /home//www/pfdev/multid9/recommended-project/web/core/lib/Drupal/Core/Render/Renderer.php(404): Drupal\Core\Render\Element::children(Array, true)
#4 /home//www/pfdev/multid9/recommended-project/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#5 /home//www/pfdev/multid9/recommended-project/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render(Array)
#6 /home//www/pfdev/multid9/recommended-project/vendor/twig/twig/src/Environment.php(418) : eval()'d code(458): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)

The othe rpost on this subject lead me to check my array sinto .theme like:

function starter_d9_2022_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
  $suggestions[] = 'views_view__' . $variables['view']->id();
  // If you want you can add a template suggestion for all views
  // based on their ID:
  $suggestions[] = sprintf('views_view__%s', $variables['view']->id());

  // Or you can check the ID, add suggestions, do whatever you want
  // ...
}
function starter_d9_2022_theme_suggestions_views_view(array $variables) {
  return [
    'views_view_display__' . $variables['view']->current_display,
    // Suggestion pour chaque affichages de la vue
  ];
}

but no effect instead of a WSOD. So I have no clue to fix this. Do someone know ?

Thanks

EDIt: after advices, it appear this correction goes wrong in the IDE(VS Code). Because of comment ?

function starter_d9_2022_theme_suggestions_views_view(array $variables) {
  //return [
    'views_view_display__' . $variables['view']->current_display;
    // Suggestion pour chaque affichages de la vue
  //];
}
Score:0
us flag

It is hard for me to realize what's your goal here, but there are few things to note:

  • $suggestions[] = 'views_view__' . $variables['view']->id(); has the same result as $suggestions[] = sprintf('views_view__%s', $variables['view']->id()); so you should take one or the other, not both.
  • inside this hook: function starter_d9_2022_theme_suggestions_views_view(array &$variables) {} (please note the ampersand), one could work directly with the $variables array and it's not needed to return anything.

As for the WSOD, in Drupal it's recommended to enable the verbose errors handling on local environment or if it's not possible, at least check the admin's logs for the error.

WebmasterPF avatar
jp flag
Thanks for your advices. I will modify the code and see if error disappear. I will keep you in touch.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.