Hi,
I have a view with relationships and contextual filters.
When the view has no results, the view crashes due to Views Tree.
Doing some debugging I was able to pinpoint to this part of the code:
$items[] = $rows[$i] . call_user_func(__FUNCTION__, $variables);
(views_tree.module line 132)
After a bit of investigation it seems this is due to the assignment above $variables['parent'] = $record->views_tree_main; assuming views_tree_main is filled in, when it is in fact 0.
By adding a check to that variable it's fixed.
So changing
foreach ($result as $i => $record) {
if ($record->views_tree_parent == $parent) {
$variables['parent'] = $record->views_tree_main;
$items[] = $rows[$i] . call_user_func(__FUNCTION__, $variables);
}
}
to
foreach ($result as $i => $record) {
if (!empty($record->views_tree_main) && $record->views_tree_parent == $parent) {
$variables['parent'] = $record->views_tree_main;
$items[] = $rows[$i] . call_user_func(__FUNCTION__, $variables);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | views-tree-empty-results-2935831.patch | 1.06 KB | robcarr |
| #2 | bug_empty_results-2935831-1.patch | 529 bytes | kyuubi |
Issue fork views_tree-2935831
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kyuubi commentedHere is the patch.
Comment #3
kyuubi commentedComment #4
a.sinitsa commentedSame problem in 8.x-2.0-alpha1 version:
Error: Call to a member function addClass() on null in template_preprocess_views_tree_table() (line 81 of modules/contrib/views_tree/views_tree.module).
Comment #5
robcarrStill relevant all these years on. PHP error only seems to appear when View not properly configured
Comment #7
robcarrPrevious patch failed due to unrelated coding standards.
Comment #9
smustgrave commentedWasn't able to reproduce but don't mind including this little defense. Will include in latest patch.
Comment #11
smustgrave commentedJK this broke tests
Comment #14
sunlixHey,
I just changed the defense check.
The tests are green and the change would prevent the view from breaking if there are no results.
Comment #15
smustgrave commentedcan we add test coverage
Comment #16
smustgrave commentedActually not able to replicate is this still an issue?
Comment #17
sunlixHey smustgrave,
yes it is replicable with 3.0.1 of views_tree.
If you have any view with views_tree set up and no entries yet the issue displays.
In my personal setup it is a views_tree view to display organizational hierarchy in the admin area.
If no organizational nodes were created yet the error appears.
The full stack trace looks like this
Comment #18
sunlixHey,
I debugged up to the missing view-style option
empty_table.If this option is true, the error appears.
I added a condition in the
template_preprocess_views_tree_tableto only iterate over the rows if there is a result.The test now deletes all entities and try to render the view to force the error if the fix is not present.
hopefully the code is good enough :-)
Comment #19
smustgrave commentedThanks for working on this. If we are adding a new key it will need a schema entry and update hook using a ConfigImporter. May be able to find time to help with that last one.
Comment #20
sunlixHey Steven,
thank you for your response.
I dont think we need any kind of schema update here.
empty_tableis already defined inDrupal\views\Plugin\views\style\Table(config schema:views.style.table)Since we lately corrected the config schema definition of
views.style.tree_tableto be type ofviews.style.tablewe are already fine with it. The plugin class do extend the core class.Do you agree?
Comment #21
smustgrave commentedBoth points are still needed. We are defining our own style so the key tree_table.empty_table does not exist
Comment #22
sunlixHey Steven,
config schema's are cascading by extending already defined types. You can visualize that behavior by printing the full extended config schema via
drushempty_tableis already defined by the inherited config type.So I really think we are good to go here.
Maybe I am missing here something. So please enlighten me if I am totally wrong. :-)
Comment #23
sunlixComment #24
smustgrave commentedI stand corrected,
Thanks!