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

Issue #3445184 by plopesc, matthieuscarset, m4olivei: Fatal error when...

Issue #3445184 by plopesc, matthieuscarset, m4olivei: Fatal error when accessing Navigation Blocks on a minimal profile installation because of the Shortcut block

(cherry picked from commit e96135b2)
parent 24e0148b
No related branches found
No related tags found
6 merge requests!122353526426-warning-for-missing,!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!8325Update file Sort.php
Pipeline #176287 passed
......@@ -59,12 +59,6 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account): AccessResultInterface {
// This navigation block requires shortcut module. Once the plugin is moved
// to the module, this should not be necessary.
if (!$this->moduleHandler->moduleExists('shortcut')) {
return AccessResult::forbidden();
}
return AccessResult::allowedIfHasPermission($account, 'access shortcuts');
}
......@@ -72,6 +66,11 @@ protected function blockAccess(AccountInterface $account): AccessResultInterface
* {@inheritdoc}
*/
public function build(): array {
// This navigation block requires shortcut module. Once the plugin is moved
// to the module, this should not be necessary.
if (!$this->moduleHandler->moduleExists('shortcut')) {
return [];
}
return [
'shortcuts' => [
// @phpstan-ignore-next-line
......
......@@ -11,11 +11,11 @@
use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase;
/**
* Tests for \Drupal\navigation\Plugin\Block\ShortcutsNavigationBlock.
* Tests for \Drupal\navigation\Plugin\Block\NavigationShortcutsBlock.
*
* @group navigation
*/
class ShortcutsNavigationBlockTest extends PageCacheTagsTestBase {
class NavigationShortcutsBlockTest extends PageCacheTagsTestBase {
use AssertPageCacheContextsAndTagsTrait;
......@@ -80,7 +80,7 @@ public function testNavigationBlock() {
// Verify that users without the 'access shortcuts' permission can't see the
// shortcuts.
$this->drupalLogin($this->drupalCreateUser(['access navigation']));
$this->assertSession()->linkNotExists('Shortcuts');
$this->assertSession()->pageTextNotContains('Shortcuts');
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
......@@ -103,6 +103,7 @@ public function testNavigationBlock() {
'access shortcuts',
'administer site configuration',
'access administration pages',
'configure any layout',
]);
// Create two different users with the same role to assert that the second
......@@ -169,44 +170,57 @@ public function testNavigationBlock() {
]);
$new_shortcut->save();
// @todo Uncomment once tests are executed against 10.3.x.
// Assign the new shortcut set to user 2 and confirm that links are changed
// automatically.
// \Drupal::entityTypeManager()
// ->getStorage('shortcut_set')
// ->assignUser($new_set, $site_configuration_user2);
// // $this->verifyDynamicPageCache($test_page_url, 'HIT');
// $this->assertSession()->linkExists('Cron');
// $this->assertSession()->linkExists('New Llama');
// // // Confirm that links for user 1 have not been affected.
// $this->drupalLogin($site_configuration_user1);
// $this->verifyDynamicPageCache($test_page_url, 'HIT');
// $this->assertSession()->linkExists('Cron');
// $this->assertSession()->linkNotExists('New Llama');
\Drupal::entityTypeManager()
->getStorage('shortcut_set')
->assignUser($new_set, $site_configuration_user2);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkExists('New Llama');
// Confirm that links for user 1 have not been affected.
$this->drupalLogin($site_configuration_user1);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkNotExists('New Llama');
// Confirm that removing assignment automatically changes the links too.
// $this->drupalLogin($site_configuration_user2);
// $this->verifyDynamicPageCache($test_page_url, 'HIT');
// $this->assertSession()->linkExists('Cron');
// $this->assertSession()->linkExists('New Llama');
// \Drupal::entityTypeManager()
// ->getStorage('shortcut_set')
// ->unassignUser($site_configuration_user2);
// $this->verifyDynamicPageCache($test_page_url, 'HIT');
// $this->assertSession()->linkExists('Cron');
// $this->assertSession()->linkNotExists('New Llama');
$this->drupalLogin($site_configuration_user2);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkExists('New Llama');
\Drupal::entityTypeManager()
->getStorage('shortcut_set')
->unassignUser($site_configuration_user2);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkNotExists('New Llama');
// Confirm that deleting a shortcut set automatically changes the links too.
// \Drupal::entityTypeManager()
// ->getStorage('shortcut_set')
// ->assignUser($new_set, $site_configuration_user2);
// $this->verifyDynamicPageCache($test_page_url, 'HIT');
// $this->assertSession()->linkExists('Cron');
// $this->assertSession()->linkExists('New Llama');
// \Drupal::entityTypeManager()
// ->getStorage('shortcut_set')
// ->delete([$new_set]);
// $this->verifyDynamicPageCache($test_page_url, 'HIT');
// $this->assertSession()->linkExists('Cron');
// $this->assertSession()->linkNotExists('New Llama');
\Drupal::entityTypeManager()
->getStorage('shortcut_set')
->assignUser($new_set, $site_configuration_user2);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkExists('New Llama');
\Drupal::entityTypeManager()
->getStorage('shortcut_set')
->delete([$new_set]);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkNotExists('New Llama');
// Verify that block disappears gracefully when shortcut module is disabled.
// Shortcut entities has to be removed first.
$link_storage = \Drupal::entityTypeManager()->getStorage('shortcut');
$link_storage->delete($link_storage->loadMultiple());
\Drupal::service('module_installer')->uninstall(['shortcut']);
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('Shortcuts');
// Confirm that Navigation Blocks page is working.
// @see https://www.drupal.org/project/drupal/issues/3445184
$this->drupalGet('/admin/config/user-interface/navigation-block');
$this->assertSession()->statusCodeEquals(200);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment