From 5c6438d055e00b0adb82e9a1661167ce9a9a7ee3 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Fri, 12 Dec 2014 16:24:01 +0000 Subject: [PATCH] Issue #2379811 by Lendude, dawehner: Views tries to render contextual links when Contextual Links module is disabled --- .../Tests/Views/NodeContextualLinksTest.php | 28 ++++++++++++++++++- core/modules/views/views.module | 6 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php b/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php index a4847fccc61..a2a8371ec4f 100644 --- a/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php +++ b/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php @@ -8,7 +8,7 @@ namespace Drupal\node\Tests\Views; use Drupal\Component\Serialization\Json; -use Symfony\Component\HttpFoundation\Request; +use Drupal\user\Entity\User; /** * Tests views contextual links on nodes. @@ -94,4 +94,30 @@ class NodeContextualLinksTest extends NodeTestBase { )); } + /** + * Tests if the node page works if Contextual Links is disabled. + * + * All views have Contextual links enabled by default, even with the + * Contextual links module disabled. This tests if no calls are done to the + * Contextual links module by views when it is disabled. + * + * @see https://www.drupal.org/node/2379811 + */ + public function testPageWithDisabledContextualModule() { + \Drupal::service('module_installer')->uninstall(['contextual']); + \Drupal::service('module_installer')->install(['views_ui']); + + // Ensure that contextual links don't get called for admin users. + $admin_user = User::load(1); + $admin_user->setPassword('new_password'); + $admin_user->pass_raw = 'new_password'; + $admin_user->save(); + + $this->drupalCreateContentType(array('type' => 'page')); + $this->drupalCreateNode(array('promote' => 1)); + + $this->drupalLogin($admin_user); + $this->drupalGet('node'); + } + } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index e6b56d10a3b..7c170dcf674 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -308,7 +308,7 @@ function views_page_display_pre_render(array $element) { */ function views_preprocess_html(&$variables) { // Early-return to prevent adding unnecessary JavaScript. - if (!\Drupal::currentUser()->hasPermission('access contextual links')) { + if (!\Drupal::moduleHandler()->moduleExists('contextual') || !\Drupal::currentUser()->hasPermission('access contextual links')) { return; } @@ -393,8 +393,8 @@ function views_preprocess_html(&$variables) { */ function views_add_contextual_links(&$render_element, $location, ViewExecutable $view, $display_id) { // Do not do anything if the view is configured to hide its administrative - // links. - if ($view->getShowAdminLinks()) { + // links or if the Contextual Links module is not enabled. + if (\Drupal::moduleHandler()->moduleExists('contextual') && $view->getShowAdminLinks()) { // Also do not do anything if the display plugin has not defined any // contextual links that are intended to be displayed in the requested // location.