Okay I have added the following custom views Preprocess function in my custom theme:

function mytheme_preprocess_views_view_unformatted(&$variables) {
  $view = $variables['view'];
  $rows = $variables['rows'];
  $style = $view->style_plugin;
  $options = $style->options;

  $variables['default_row_class'] = !empty($options['default_row_class']);
  foreach ($rows as $id => $row) {
    $variables['rows'][$id] = [];
    $variables['rows'][$id]['id'] = $id;
    $variables['rows'][$id]['content'] = $row;
    $variables['rows'][$id]['attributes'] = new Attribute();
    if ($row_class = $view->style_plugin->getRowClass($id)) {

and I am getting the following error messages:

User error: "attributes" is an invalid render array key in Drupal\Core\Render\Element::children() (line 98 of ../core/lib/Drupal/Core/Render/Element.php)

It is exactly the same as the code which comes with default core views module, except just one line difference

$variables['rows'][$id]['id'] = $id;

As soon as I remove this whole function from my custom theme, the error messages disappear. It is very strange that the exact same code in Drupal Core Views Module works but giving error when I add it in my custom theme. Any ideas?

  • Is this helpful? drupal.stackexchange.com/questions/253594/…
    – cilefen
    Jul 18 at 13:16
  • No actually I tried almost all solutions already present for similar errors. The exact same code works in views.theme.inc file without error but not in my custom theme file. If it is a problem with template, the same code in both places should give errors as the template is same in both cases.
    – Sami
    Jul 18 at 15:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.