diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php index 392c3d8..6ff6936 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php @@ -26,6 +26,7 @@ * "list" = "Drupal\shortcut\ShortcutSetListController", * "form" = { * "default" = "Drupal\shortcut\ShortcutSetFormController", + * "add" = "Drupal\shortcut\ShortcutSetFormController", * "edit" = "Drupal\shortcut\ShortcutSetFormController", * "customize" = "Drupal\shortcut\Form\SetCustomize", * "delete" = "Drupal\shortcut\Form\ShortcutSetDeleteForm" diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetAccessController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetAccessController.php index ba8ba2c..f42c20d 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetAccessController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetAccessController.php @@ -20,14 +20,14 @@ class ShortcutSetAccessController extends EntityAccessController { * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { + $account = $this->prepareUser($account); switch ($operation) { - case 'create': case 'update': if ($account->hasPermission('administer shortcuts')) { return TRUE; } if ($account->hasPermission('customize shortcut links')) { - return !isset($entity) || $entity == shortcut_current_displayed_set($account); + return $entity == shortcut_current_displayed_set($account); } return FALSE; break; @@ -41,4 +41,12 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } } + /** + * {@inheritdoc} + */ + public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array()) { + $account = $this->prepareUser($account); + return $account->hasPermission('administer shortcuts') || $account->hasPermission('customize shortcut links'); + } + } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutSetsTest.php b/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutSetsTest.php index 4222f71..4e4959c 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutSetsTest.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutSetsTest.php @@ -7,8 +7,6 @@ namespace Drupal\shortcut\Tests; -use Drupal\simpletest\WebTestBase; - /** * Defines shortcut set test cases. */ @@ -26,9 +24,15 @@ public static function getInfo() { * Tests creating a shortcut set. */ function testShortcutSetAdd() { - $new_set = $this->generateShortcutSet($this->randomName()); - $sets = entity_load_multiple('shortcut_set'); - $this->assertTrue(isset($sets[$new_set->id()]), 'Successfully created a shortcut set.'); + $this->drupalGet('admin/config/user-interface/shortcut'); + $this->clickLink(t('Add shortcut set')); + $edit = array( + 'label' => $this->randomName(), + 'id' => strtolower($this->randomName()), + ); + $this->drupalPost(NULL, $edit, t('Save')); + $new_set = $this->container->get('entity.manager')->getStorageController('shortcut_set')->load($edit['id']); + $this->assertIdentical($new_set->id(), $edit['id'], 'Successfully created a shortcut set.'); $this->drupalGet('user/' . $this->admin_user->id() . '/shortcuts'); $this->assertText($new_set->label(), 'Generated shortcut set was listed as a choice on the user account page.'); }