Problem/Motivation
The following notice message is being thrown:
Notice: Undefined property: Drupal\views\ViewExecutable::$render_time in Drupal\views_ui\ViewUI->renderPreview() (line 715 of core/modules/views_ui/src/ViewUI.php).
This is actually just a symptom of a deeper issue, which is that the views statistics information is only displayed if the query is configured to display (and then, due to the notice, render time is always blank).
Proposed resolution
Add tests to ensure that statistics are displayed (if so configured) even if the query is set to not be displayed. This will also fix the PHP notice.
Remaining tasks
Make a patch
- Test the patch
User interface changes
N/A
API changes
N/A
Comments
Comment #1
sachbearbeiter commentedviews settings
Comment #2
sachbearbeiter commentedview
Comment #3
dawehnerNote:
should be
Comment #4
dawehnerAdds a novice tag.
Comment #5
zealfire commentedPlease review.
Thanks.
Comment #7
zealfire commented@dawehner,i think the above assignment is wrong because the return type of Timer::stop('entity.view.preview_form'); is array type but of $render_time is int.Please give you opinion.
Comment #8
adci_contributor commentedjust fix corrupted endline in patch
Comment #9
dawehnerThank you @zealfire
Now it would be nice if we could have some kind of testcoverage.
Comment #10
mcmilo commentedI am unable to reproduce this issue. After imported the view using settings in #2 and place its block in the sidebar I do not get the notice reported in the summary, instead I am getting a different notice that says:
Notice: Undefined index: #rows in Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender() (line 2064 of /Users/ccortes/Projects/drupalcon/sprint/drupal8/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php).The steps I am following to reproduce this issue are:
Additional details: Applying the patch does not remove the notice message I am getting. Also, If the "Public Exhibitors" view block is disable the notice message is not displayed anymore.
Comment #11
jhedstromThis can probably be removed since with this fix, that variable no longer exists on the
ViewUIclass.Comment #12
jhedstromEr, actually,
render_timeisn't defined on theViewExecutableclass either, so the fix here should probably consistently use$this->render_timeinstead of$this->executable->render_time.Comment #13
fgmPatched on ViewUI.
Comment #14
fgmOops, wrong patch.
Comment #16
dawehnerRight fix.
Comment #17
alexpottStill needs tests - no?
Comment #18
jhedstromI'm working on a test (good thing, because it's uncovering several issues).
Comment #19
jhedstromSo, statistic display is currently tied very tightly to query display, to the point that it doesn't display at all unless queries are also displayed.
I've updated the issue to indicate this (the php notice is just a symptom of further broken logic).
Comment #20
jhedstromComment #21
jhedstromComment #22
jhedstromComment #24
dawehnerShould we not test that the query is somehow displayed? Its confusing that we have twice the same asserts
Comment #25
lendudePer #24, added tests to check if Query is shown or not with different settings.
Comment #26
dawehnerWell + the actual query, not just the title?
Comment #27
lendudeplus the actual query now.
Comment #28
dawehnerGreat, thank you. IMHO this is enough
Comment #29
xjmSooo, technically, these are public properties on ViewUI. But they are never used nor set in core, and here they are only being declared as null. Therefore, these hunks are just essentially removing wrong class documentation. If other code sets public properties on a ViewUI instance, well ballyhoo, good for them. It shouldn't affect their code at all since Views doesn't do anything with it ever.
So this looks okay for 8.0.x to me.
Comment #30
alexpottWhat is really confusing about this change is that the whole outer
if ($show_location === 'above' || $show_location === 'below') {is unnecessary Since the only possible values are above or below. Let's remove that here now we're adding testing.Comment #31
alexpottAlso it's be great if the testing could be improved to cover both the above and below cases.
Comment #32
lendudeBit of a clean up as suggested in #30. Also took out the double check for $show_stats and $show_location since both contain the same information if $show_stats is set, so testing only $show_location should be enough.
Added a test for above and below. Not sure if this is the most elegant way to do it, but seems to work.
Comment #33
dawehnerIMHO we should use float here.
So I'm wondering whether we need the if in the first place. Can't we provide a default empty
$rows['query']bit?Comment #34
lendude#33.1 Timer returns a float, so yeah that makes more sense.
#33.2 Cleaned it up a bit, initialised the arrays before they get filled so they can just be merged later without worrying about what's in there.
Also cleaned up the ifelse since, like @alexpott pointed out in #30, 'above' and 'below' are the only options, seems pointless to specifically test for both, one should be enough.
Comment #35
dawehnerNice, this is much better now!
Comment #37
lendudeUnrelated fail, back to RTBC.
Comment #38
alexpottWe're removing public properties that do nothing (and because of this I think it okay to remove), making the code easier to understand, fixing a bug and adding a test. Nice.
Committed 5fd3567 and pushed to 8.0.x and 8.1x. Thanks!