Issue #2379811 by Lendude, dawehner: Views tries to render contextual links when Contextual Links module is disabled

8.0.x
Nathaniel Catchpole 2014-12-12 16:24:01 +00:00
parent a17498c593
commit 5c6438d055
2 changed files with 30 additions and 4 deletions

View File

@ -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');
}
}

View File

@ -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.