Problem/Motivation
Visiting the default (formerly master) display for the media_library view's configuration page results in a dblog/watchdog php notice. Well, two actually:
Notice: Undefined index: defaults in seven_views_pre_render() (line 351 of /var/lib/tugboat/stm/web/core/themes/seven/seven.theme)
and
Notice: Undefined index: defaults in media_library_views_pre_render() (line 181 of /var/lib/tugboat/stm/web/core/modules/media_library/media_library.module)
I imagine this is unlikely to be seen by most since it requires having the "Always show the master (default) display" checkbox checked (or set in settings.local.php or whatever), and I honestly don't know even know if it's really a problem that could cause any real-world issues, but since my team's development workflow includes checking the dblog for potential issues in every PR, I wasted some time thinking my edit to that view caused a bug/regression.
Steps to reproduce
- Enable (or have enabled)
mediaandmedia_library. - Go to
/admin/structure/views/settingsand check the "Always show the default display" checkbox. Save the page. - Visit
/admin/structure/views/view/media_library(and/or maybe just go directly to/admin/structure/views/view/media_library/edit/defaultwithout having to do the previous step?) - Visit
/admin/reports/dblogand see the two new notices.
Proposed resolution
Of course an isset() or array_key_exists() or whatever could be added to those lines in the .module and .theme files, though I don't know if maybe the default display ought to be getting that ['defaults'] key also fed to it instead? (Or maybe those classes should be added regardless of whether ['defaults'] exists or whatever? I don't quite know what all the two hook_views_pre_render()s are doing in the first place.)
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 3217907-18.patch | 2.7 KB | smustgrave |
| #18 | interdiff-15-18.txt | 3.24 KB | smustgrave |
| #18 | 3217907-18-tests-only.patch | 1.78 KB | smustgrave |
Issue fork drupal-3217907
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 #4
mohit.bansal623 commentedisset conditions added in both .theme and .module files.
Comment #6
kristen polThanks for the issue and MR.
1. Changing to 9.4.
2. Patch applies with offsets for Drupal 9.3, 9.4, and 10.
3. Patch is very simple change.
4. Needs screenshots of before fix and after fix.
5. Needs manual testing on 9.4.
Comment #7
kmonahan commentedTested on 9.4. Reproduced the issue following the steps in the ticket (see screenshots before1-3). Cleared the database log and applied the patch. Patch applied cleanly and reproduction steps no longer cause the issue (see screenshot after, showing the still-empty database log).
Comment #8
kmonahan commentedComment #9
alexpottThis points to the fact we have an untested code. It'd be great to add automated test coverage for it. \Drupal\Tests\media_library\FunctionalJavascript\ViewsUiIntegrationTest looks a good place to add it.
Comment #11
rakhi soni commentedKindly review patch for branch 9.5x,,
Comment #12
aarti zikre commentedVerified on 9.5x dev drupal version. Now unable to reproduce the issue. Please check the below screenshot.
Steps performed :
1. Enable (or have enabled) media and media_library.
2. Go to /admin/structure/views/settings and check the "Always show the default display" checkbox. Save the page.
3. Visit /admin/structure/views/view/media_library
4. View the notices
5. Applied patch
6. follow step 3
Comment #13
quietone commented@aarti zikre, when adding screenshot please add them to the Issue Summary so it helps committers and reviewers find the latest. Not so important here as this issue only has a few comments so far but it does make a big difference on issues with many comments and sets of screenshots.
This is tagged as 'needs tests' and there are not tests in the patch. Tests were asked for in #9.
The proposed resolution section of the Issue Summary is full of questions. It should be a statement of what is being changed and why so the reviewer can determine that the intended fix was implements. Adding tag for an issue summary update.
Comment #14
smustgrave commentedAlso seeing this issue with claro. So makes me think patching seven or theme isn't the approach.
Comment #15
smustgrave commentedAdding a test. and added a line to the media_library.module that solves the warning without having to edit any of the themes.
Issue summary seemed clear to me (least the testing steps) so not sure if that label could be removed.
Comment #16
larowlanStill needs tests, see #9
Comment #17
smustgrave commentedAdded a tests patch but looks like the regular one failed
Comment #18
smustgrave commentedTook a different approach for the tests but should work.
Comment #20
Munavijayalakshmi commentedPatch #18 resolved the issue.
Comment #21
Munavijayalakshmi commentedComment #22
kristen pol@Munavijayalakshmi Thanks for testing.
This still needs code review and core gate checks.
This does not need more manual testing, thanks!
Comment #24
phenaproximaI wonder if this is a problem for all views, by default. Does Views simply not add the
css_classkey to the default display normally, and therefore any view would be affected by this problem, if it had a hook trying to access['defaults']['css_class']?Then again, Media Library is the module that's implementing hook_views_pre_view, so it should be acting more defensively. Therefore, I think this makes sense.
Comment #25
phenaproximaActually, one question: why do we need this section, or indeed, why does this need to be a functional test? We're rendering the view programmatically in this test, so in theory, wouldn't we get this error even if we weren't interacting with the UI?
Comment #26
smustgrave commentedMoving to NW to convert test to a kernel test.
Comment #27
smustgrave commentedConverted to kernel
Comment #28
phenaproximaAssuming this passes tests, I like it.
Comment #29
larowlanUnfortunately that test doesn't fail without the fix
Comment #30
smustgrave commentedSo what is we go back to functional tests in #18 those do fail.
Comment #31
borisson_I agree that #18 is a good solution. Code looks great and I can't find anything that needs to change.
Comment #33
quietone commentedComments should help the user understand the test. For me, this is merely a statement of the obvious. As someone who does not know the render system this is meaningless.
Also, the title of this is an error message, can we change it to what is being fixed?
It is always challenging to decide to push back on such matters but these details help those who come behind us.