diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js index 7f93a15f4dda0030782ba8ab940a8a9647ed6c9a..558ea105cc2f8108ccd42caaa4be7dd05d78aca0 100644 --- a/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -163,7 +163,7 @@ // Update all contextual links placeholders whose HTML is cached. var uncachedIDs = _.filter(ids, function initIfCached(contextualID) { var html = storage.getItem('Drupal.contextual.' + contextualID); - if (html !== null) { + if (html && html.length) { // Initialize after the current execution cycle, to make the AJAX // request for retrieving the uncached contextual links as soon as // possible, but also to ensure that other Drupal behaviors have had diff --git a/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php new file mode 100644 index 0000000000000000000000000000000000000000..12ce10db8bd2b5cac2086fa995e421bb637049b8 --- /dev/null +++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php @@ -0,0 +1,62 @@ +placeBlock('system_branding_block', ['id' => 'branding']); + } + + /** + * Tests the visibility of contextual links. + */ + public function testContextualLinksVisibility() { + $this->drupalLogin($this->drupalCreateUser([ + 'access contextual links' + ])); + + $this->drupalGet('user'); + $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); + $this->assertEmpty($contextualLinks); + + // Ensure visibility remains correct after cached paged load. + $this->drupalGet('user'); + $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); + $this->assertEmpty($contextualLinks); + + // Grant permissions to use contextual links on blocks. + $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [ + 'access contextual links', + 'administer blocks', + ]); + + $this->drupalGet('user'); + $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); + $this->assertNotEmpty($contextualLinks); + + // Ensure visibility remains correct after cached paged load. + $this->drupalGet('user'); + $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); + $this->assertNotEmpty($contextualLinks); + } + +}