Skip to content
Snippets Groups Projects
Commit 6ef8c1e2 authored by catch's avatar catch
Browse files

Issue #3426624 by plopesc, smustgrave: Shortcuts Block does not include the necessary cache tags

parent 4229a611
No related branches found
No related tags found
31 merge requests!12227Issue #3181946 by jonmcl, mglaman,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #117356 passed with warnings
Pipeline: drupal

#117357

    ......@@ -23,7 +23,12 @@ class ShortcutsBlock extends BlockBase {
    */
    public function build() {
    return [
    shortcut_renderable_links(shortcut_current_displayed_set()),
    '#lazy_builder' => ['shortcut.lazy_builders:lazyLinks', [FALSE]],
    '#create_placeholder' => TRUE,
    '#cache' => [
    'keys' => ['shortcut_set_block_links'],
    'contexts' => ['user'],
    ],
    ];
    }
    ......
    ......@@ -38,16 +38,19 @@ public static function trustedCallbacks() {
    /**
    * #lazy_builder callback; builds shortcut toolbar links.
    *
    * @param bool $show_configure_link
    * Boolean to indicate whether to include the configure link or not.
    *
    * @return array
    * A renderable array of shortcut links.
    */
    public function lazyLinks() {
    public function lazyLinks(bool $show_configure_link = TRUE) {
    $shortcut_set = shortcut_current_displayed_set();
    $links = shortcut_renderable_links();
    $configure_link = NULL;
    if (shortcut_set_edit_access($shortcut_set)->isAllowed()) {
    if ($show_configure_link && shortcut_set_edit_access($shortcut_set)->isAllowed()) {
    $configure_link = [
    '#type' => 'link',
    '#title' => t('Edit shortcuts'),
    ......
    ......@@ -205,4 +205,124 @@ public function testToolbar() {
    $this->assertSession()->linkNotExists('Alpaca');
    }
    /**
    * Tests visibility and cacheability of shortcuts in the block.
    */
    public function testBlock(): void {
    $this->drupalPlaceBlock('page_title_block', ['id' => 'title']);
    $this->drupalPlaceBlock('shortcuts', [
    'id' => 'shortcuts',
    'label' => 'Shortcuts Block',
    ]);
    $test_page_url = Url::fromRoute('test_page_test.test_page');
    $this->verifyPageCache($test_page_url, 'MISS');
    $this->verifyPageCache($test_page_url, 'HIT');
    // Ensure that without enabling the shortcuts-in-page-title-link feature
    // in the theme, the shortcut_list cache tag is not added to the page.
    $this->drupalLogin($this->rootUser);
    $this->drupalGet('admin/config/system/cron');
    $expected_cache_tags = [
    'CACHE_MISS_IF_UNCACHEABLE_HTTP_METHOD:form',
    'block_view',
    'config:block.block.shortcuts',
    'config:block.block.title',
    'config:block_list',
    'config:shortcut.set.default',
    'config:system.menu.admin',
    'config:system.theme',
    'rendered',
    ];
    $this->assertCacheTags($expected_cache_tags);
    \Drupal::configFactory()
    ->getEditable('stark.settings')
    ->set('third_party_settings.shortcut.module_link', TRUE)
    ->save(TRUE);
    // Add cron to the default shortcut set, now the shortcut list cache tag
    // is expected.
    $this->drupalGet('admin/config/system/cron');
    $this->clickLink('Add to Default shortcuts');
    $expected_cache_tags[] = 'config:shortcut_set_list';
    $this->assertCacheTags($expected_cache_tags);
    // Verify that users without the 'access shortcuts' permission can't see the
    // shortcuts.
    $this->drupalLogin($this->drupalCreateUser());
    $this->assertSession()->pageTextNotContains('Shortcuts Block');
    $this->verifyDynamicPageCache($test_page_url, 'MISS');
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    // Verify that users without the 'administer site configuration' permission
    // can't see the cron shortcut but can see the block.
    $this->drupalLogin($this->drupalCreateUser([
    'access shortcuts',
    ]));
    $this->verifyDynamicPageCache($test_page_url, 'MISS');
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertSession()->pageTextContains('Shortcuts Block');
    $this->assertSession()->linkNotExists('Cron');
    // Create a role with access to shortcuts as well as the necessary
    // permissions to see specific shortcuts.
    $site_configuration_role = $this->drupalCreateRole([
    'access shortcuts',
    'administer site configuration',
    'access administration pages',
    ]);
    // Create two different users with the same role to assert that the second
    // user has a cache hit despite the user cache context, as
    // the returned cache contexts include those from lazy-builder content.
    $site_configuration_user1 = $this->drupalCreateUser();
    $site_configuration_user1->addRole($site_configuration_role);
    $site_configuration_user1->save();
    $site_configuration_user2 = $this->drupalCreateUser();
    $site_configuration_user2->addRole($site_configuration_role);
    $site_configuration_user2->save();
    $this->drupalLogin($site_configuration_user1);
    $this->verifyDynamicPageCache($test_page_url, 'MISS');
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertCacheContexts(['user', 'url.query_args:_wrapper_format']);
    $this->assertSession()->pageTextContains('Shortcuts Block');
    $this->assertSession()->linkExists('Cron');
    $this->drupalLogin($site_configuration_user2);
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertCacheContexts(['user', 'url.query_args:_wrapper_format']);
    $this->assertSession()->pageTextContains('Shortcuts Block');
    $this->assertSession()->linkExists('Cron');
    // Add another shortcut.
    $shortcut = Shortcut::create([
    'shortcut_set' => 'default',
    'title' => 'Llama',
    'weight' => 0,
    'link' => [['uri' => 'internal:/admin/config']],
    ]);
    $shortcut->save();
    // The shortcuts are displayed in a lazy builder, so the page is still a
    // cache HIT but shows the new shortcut immediately.
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertSession()->linkExists('Cron');
    $this->assertSession()->linkExists('Llama');
    // Update the shortcut title and assert that it is updated.
    $shortcut->set('title', 'Alpaca');
    $shortcut->save();
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertSession()->linkExists('Cron');
    $this->assertSession()->linkExists('Alpaca');
    // Delete the shortcut and assert that the link is gone.
    $shortcut->delete();
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertSession()->linkExists('Cron');
    $this->assertSession()->linkNotExists('Alpaca');
    }
    }
    • catch @catch

      mentioned in commit ee03e025

      ·

      mentioned in commit ee03e025

      Toggle commit list
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment