- Issue created by @_randy
- π©πͺGermany marc.bau
Have seen the same issue and not found a solution yet.
- Status changed to Postponed: needs info
2 months ago 2:45pm 10 September 2024 - πΊπΈUnited States shelane
Can you give me more info on steps to reproduce this issue? What style did you have it set to? What are the options? What is the data type in the view?
- π¨π¦Canada _randy
@shelane
The data in the view is two content types (just regular old nodes).
Configured to show rendered entity content, not fields, using a specific display mode.Format: Bootstrap Grid - Settings were straight out of the box - no changes.
As noted, this worked fine prior to the Beta and RC releases.
Issue is in template_preprocess_views_bootstrap_grid function in views_bootstrap.theme.inc file.
In the alpha version only $vars['row_attributes'] was set to "new Attribute()".
In the latest versions, $vars['attributes'] is set to "new Attribute(['class' => 'grid']);"This creates the issue with Drupal core.
- π©πͺGermany marc.bau
Same here - "Format: Bootstrap Grid - Settings were straight out of the box - no changes."
- πΊπΈUnited States shelane
Interesting. I still haven't been able to recreate the issue. Looking right at the Drupal core views module and their views.theme.inc file uses the
new Attribute
method. For instance:foreach ($variables['rows'] as $num => $row) { $variables['rows'][$num]['attributes'] = []; if ($row_class = $handler->getRowClass($num)) { $variables['rows'][$num]['attributes']['class'][] = $row_class; } $variables['rows'][$num]['attributes'] = new Attribute($variables['rows'][$num]['attributes']); } if (empty($variables['rows']) && !empty($options['empty_table'])) { $build = $view->display_handler->renderArea('empty'); $variables['rows'][0]['columns'][0]['content'][0]['field_output'] = $build; $variables['rows'][0]['attributes'] = new Attribute(['class' => ['odd']]); // Calculate the amounts of rows with output. $variables['rows'][0]['columns'][0]['attributes'] = new Attribute([ 'colspan' => count($variables['header']), 'class' => ['views-empty'], ]); }
I also see it in the 9.5.x branch code base.
- π¨π¦Canada _randy
Specifically in my case, it's the following that is the issue:
$vars['rows'][$id]['attributes'] = new Attribute(); if ($row_class = $view->style_plugin->getRowClass($id)) { $vars['rows'][$id]['attributes']->addClass($row_class); } $vars['rows'][$id]['attributes']->addClass($col_classes); }
If I comment out the
$vars['rows'][$id]['attributes'] = new Attribute();
and the$vars['rows'][$id]['attributes']->addClass($col_classes);
lines, it works just fine.I haven't had a chance to dig further why it's the row attributes. The only thing I can think of right now is that we're not using fields? We're using display modes on rendered entities. Not sure.
- πΊπΈUnited States shelane
Can you post a screenshot of your views settings for me?
- π¨π¦Canada _randy
I've added 2 screenshots. But I don't think they'll help.
You're 100% right in that this works out of the box (I tried on simplytest.me)
Perhaps this is a Bootstrap5 theme related issue or something in Layout Builder ( https://www.drupal.org/project/bootstrap5 β ).
But it manifests itself first here. I'll have to dig some more.
- πΊπΈUnited States shelane
I installed the Bootstrap5 theme (previously used Barrio for testing) and it worked fine with a similar setup. I don't use Layout Builder, so I'm not sure how I would set that up to test to see if that's associated.
Do you see this happening on any type other than grid?
Out of curiosity, have you tried default responsive grid option? I think it works great and even with Bootstrap, it's my preferred grid.
- π©πͺGermany marc.bau
I think I had this issue when I tried to added a css class via a preprocess function to something. The bad - I deleted the code and cannot remember it exactly.
- Merge request !39optimizes row construction and variable declarations β (Closed) created by shelane
- πΊπΈUnited States shelane
I wish that I could readily recreate this issue. I made some minor changes but since I can't recreate the problem, I can't confirm this fixes anything.
- πΊπΈUnited States shelane
I have made the code changes that I had in this MR in the related issue. There is now a new release. As I said, since I can't recreate the error described, I'm not sure if this fixed it or not. Let me know. If it does not, the more information you can provide me on how to recreate it, the better.
- π¨π¦Canada _randy
@shelane
I'll give this a go in the next few days. I appreciate the update and attempt. - π¨π¦Canada _randy
For anyone else who runs into this problem with this module or any others that provide attributes during the render process:
I found where, not necessarily why, this issue occurs.
This issue manifests itself during rendering of a Twig template specifically when you are looping over view output rows.
If you have a twig template for a specific view and display, you'll probably do something like this within it:<div class="wrapper"> {% for row in rows %} <div class="output-card"> {{ row }} </div> {% endfor %} </div>
This worked up until ~Drupal 10.2.9. For whatever reason in D10.3+ in conjunction with this module, you'd get an error thrown about "attributes" being an object, not an array.
The fix for this issue was to change the output in the Twig template to:
<div class="wrapper"> {% for row in rows %} <div class="output-card"> <div{{ row.attributes }}>{{ row.content }}</div> </div> {% endfor %} </div>
Where you now must output the row attributes separately from the row content.
Thanks to @shelane for poking around enough until I was able to find a solution to the issue!
- πΊπΈUnited States shelane
Does this mean that I can mark this as fixed?
- π΅π±Poland piotr pakulski Poland πͺπΊ
#20 helped me with solving this error - not for this module but for some custom implementation. Thanks - this is the path for fixing this error.