Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292339

Contextual links button is always rendered even when no links are available

$
0
0

The contextual link button is always rendered even when no links are available.

Use case: A user with a limited role but with the use contextual permissions but no block permissions will see the contextual filter button for the blocks without the links.

function initContextual($contextual, html) {
    var $region = $contextual.closest('.contextual-region');
    var contextual = Drupal.contextual;
  
    $contextual
      // Update the placeholder to contain its rendered contextual links.
      .html(html)
      // Use the placeholder as a wrapper with a specific class to provide
      // positioning and behavior attachment context.
      .addClass('contextual')
      // Ensure a trigger element exists before the actual contextual links.
      .prepend(Drupal.theme('contextualTrigger'));

    // Set the destination parameter on each of the contextual links.
    var destination = 'destination=' + Drupal.encodePath(drupalSettings.path.currentPath);
    $contextual.find('.contextual-links a').each(function () {
      var url = this.getAttribute('href');
      var glue = (url.indexOf('?') === -1) ? '?' : '&';
      this.setAttribute('href', url + glue + destination);
    });

The prepend(Drupal.theme('contextualTrigger')) is always added even when there are no links.
A check should be done before adding the the contextual elements.

function initContextual($contextual, html) {
    if ($(html).find('a').length === 0) {
      return;
    }

    var $region = $contextual.closest('.contextual-region');
    var contextual = Drupal.contextual;

    $contextual
      // Update the placeholder to contain its rendered contextual links.
      .html(html)
     ...

I don' think that an action is required when there are no links.


Viewing all articles
Browse latest Browse all 292339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>