This only applies when logged in as user 1.
Happens after changes done in https://www.drupal.org/node/2352155
By default 'Show contextual links' is enabled for all views, even if the Contextual Links module is disabled. views_preprocess_html only checks if the user has the 'access contextual links' permission, not if the module is enabled. So for user 1 this will return TRUE even if the Contextual Links module is disabled.
If there are contextual links it calls _contextual_links_to_id() and gives:
Fatal error: Call to undefined function _contextual_links_to_id()
Steps to reproduce:
Go to a view page as user 1, with Contextual Links module disabled on a view where 'Show contextual links' is enabled.
Possible Solutions I see:
Add calls to \Drupal::moduleHandler()->moduleExists('contextual')
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | interdiff-2379811-9-12.txt | 1.29 KB | lendude |
| #12 | 2379811-12.patch | 2.76 KB | lendude |
| #9 | 2379811-9.patch | 2.76 KB | lendude |
| #6 | 2379811-fail.patch | 1.56 KB | dawehner |
Comments
Comment #1
lendudeComment #2
lendudeI made a patch that adds a call to \Drupal::moduleHandler()->moduleExists('contextual') in a logical spot, namely views_add_contextual_links(). That function shouldn't do anything if the Contextual Links module is disabled, this makes sure it doesn't.
However, the call to _contextual_links_to_id() happens in views_preprocess_html(), and if somehow $variables['page']['#views_contextual_links'] get set to TRUE (which should only happen by a call to views_add_contextual_links(), but who knows), this bug will still occur.
So should we add another call to \Drupal::moduleHandler()->moduleExists('contextual') in views_preprocess_html() too?
Comment #3
pfrenssenYes I would do that as it makes it more robust. At the moment the only place where
#views_contextual_linksis set is inviews_add_contextual_links(), but this might get used in contrib and custom modules / themes. Looking at the history of this code in #914382: Contextual links incompatible with render cache this was originally only running when the Contextual Links module was enabled, inviews_contextual_links_view_alter().This also needs a test.
Comment #4
lendudeNew patch with added extra check.
I talked to @Xano about writing a test for this when I found the bug and his reply was basically : "Yeah, good luck with that..."
Took a stab at it and yeah, no joy.
So, I'll leave that for somebody else to do if it's really needed.
Comment #5
dawehnerthe fixes done here are looking perfect.
Are you sure we need to do more than creating a test which enables views but not enable contextual.
Once done, we create a page view, or rather reuse some of the existing test views and it should not break.
Given that I kinda think that this issue is more important than just normal, given that its a fatal error for the admin user.
Login as admin user is not hard in a test, just do a
User::load(1)and then use$this->drupalLoginwith it.Comment #6
dawehnerYou can easy JUST enable the standard module, disable context and check that the frontpage is broken for the admin.
There is no way that this is not critical, sorry ...
Comment #8
pfrenssenLeftover debugging cruft.
Hmm well this is obviously correct when you have intimate knowledge of the actual bug that we are fixing here, but it is not clear how this comment is related to what the test code is actually doing: simply logging in and retrieving the node overview.
Maybe we can add a docblock explaining that this is a regression test for a very particular bug, and link to this issue? Something like this:
Apart from these two minor remarks this is looking good.
Comment #9
lendudeRerolled with #8 in mind.
1. fixed
2. I agree, some explanation would be good. I made the docblock a little more general since this test is really for 'do views render when Contextual Links is disabled but the views setting says they should be shown'.
Comment #10
catchCould we open a follow-up to not have views module calling out to private contextual module functions? That looks really odd.
For the quick fix this is looking good though.
We should reverse the condition I think.
The permissions check could one day throw an exception if the permission doesn't exist in the system, it doesn't at the moment but there have been attempts to fix that before.
Same here with the reversal I think.
Comment #11
catchWas trying to figure out how critical this is.
So it only affects user 1, however it's a fatal error just on visiting any page where this code runs, so if you had a view in a block in both front end and admin themes , it'd be completely unrecoverable - can't even log out to log in as a different admin user.
You'd have to 1. already have a different admin user in the system to log in as - if you don't then you're down to drush 2. have to use another browser or clear cookies to log in as that user.
So it's a bit borderline since you have to do some work to get into this situation, but could leave people with no mitigation once they do. Also new users are more likely to be browsing around as user/1 since that's how we set them up in the installer.
Comment #12
lendudeYeah the private function call is not good.
Reversed the conditions. Also the check in views_preprocess_html should have been an OR not an AND, so fixed that.
Comment #13
lendudeNow with the right interdiff...
Comment #14
dawehnerOh, good idea with the OR.
For me this is now looking fine.
Comment #15
catchOpened #2392469: views_preprocess_html() calls private contextual module function.
Committed/pushed to 8.0.x thanks!
Comment #17
alexpottThis issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed bfb69f6 and pushed to 8.0.x. Thanks!
Comment #18
pfrenssenFollowup to address the call to the private function
_contextual_links_to_id()is #2392469: views_preprocess_html() calls private contextual module function.