diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 3c8f087..b4317eb 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -10,6 +10,7 @@ use Drupal\Component\Uuid\Uuid; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityMalformedException; +use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityStorageControllerBase; use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigFactory; @@ -70,6 +71,13 @@ class ConfigStorageController extends EntityStorageControllerBase { protected $entityQueryFactory; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** * Constructs a ConfigStorageController object. * * @param string $entity_type @@ -82,8 +90,11 @@ class ConfigStorageController extends EntityStorageControllerBase { * The config storage service. * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory * The entity query factory. + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. + */ - public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory) { + public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, EntityManager $entity_manager) { parent::__construct($entity_type, $entity_info); $this->idKey = $this->entityInfo['entity_keys']['id']; @@ -98,6 +109,7 @@ public function __construct($entity_type, array $entity_info, ConfigFactory $con $this->configFactory = $config_factory; $this->configStorage = $config_storage; $this->entityQueryFactory = $entity_query_factory; + $this->entityManager = $entity_manager; } /** @@ -109,7 +121,8 @@ public static function createInstance(ContainerInterface $container, $entity_typ $entity_info, $container->get('config.factory'), $container->get('config.storage'), - $container->get('entity.query') + $container->get('entity.query'), + $container->get('plugin.manager.entity') ); } diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php index f9ce249..2641a85 100644 --- a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php @@ -35,13 +35,6 @@ class FieldInstanceStorageController extends ConfigStorageController { protected $moduleHandler; /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManager - */ - protected $entityManager; - - /** * The state keyvalue collection. * * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface @@ -67,8 +60,7 @@ class FieldInstanceStorageController extends ConfigStorageController { * The state key value store. */ public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, EntityManager $entity_manager, ModuleHandler $module_handler, KeyValueStoreInterface $state) { - parent::__construct($entity_type, $entity_info, $config_factory, $config_storage, $entity_query_factory); - $this->entityManager = $entity_manager; + parent::__construct($entity_type, $entity_info, $config_factory, $config_storage, $entity_query_factory, $entity_manager); $this->moduleHandler = $module_handler; $this->state = $state; } diff --git a/core/modules/field/lib/Drupal/field/FieldStorageController.php b/core/modules/field/lib/Drupal/field/FieldStorageController.php index 41efe60..461e4c5 100644 --- a/core/modules/field/lib/Drupal/field/FieldStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldStorageController.php @@ -30,13 +30,6 @@ class FieldStorageController extends ConfigStorageController { protected $moduleHandler; /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManager - */ - protected $entityManager; - - /** * The state keyvalue collection. * * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface @@ -62,9 +55,8 @@ class FieldStorageController extends ConfigStorageController { * The state key value store. */ public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, EntityManager $entity_manager, ModuleHandler $module_handler, KeyValueStoreInterface $state) { - parent::__construct($entity_type, $entity_info, $config_factory, $config_storage, $entity_query_factory); + parent::__construct($entity_type, $entity_info, $config_factory, $config_storage, $entity_query_factory, $entity_manager); - $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; $this->state = $state; } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkDeleteAccessCheck.php b/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkDeleteAccessCheck.php deleted file mode 100644 index 6fad35c..0000000 --- a/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkDeleteAccessCheck.php +++ /dev/null @@ -1,37 +0,0 @@ -attributes->get('menu_link'); - $set_name = str_replace('shortcut-', '', $menu_link['menu_name']); - if ($shortcut_set = shortcut_set_load($set_name)) { - return shortcut_set_edit_access($shortcut_set); - } - } - -} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutCreateAccessCheck.php b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutCreateAccessCheck.php new file mode 100644 index 0000000..dfc69ef --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutCreateAccessCheck.php @@ -0,0 +1,35 @@ +getRequirement($this->requirementsKey); + if ($shortcut_set = $request->attributes->get('shortcut_set')) { + return $this->entityManager->getAccessController($entity_type)->createAccess($shortcut_set->id()); + } + return parent::access($route, $request); + } + +} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutController.php b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutController.php new file mode 100644 index 0000000..34ce433 --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutController.php @@ -0,0 +1,89 @@ +moduleHandler = $module_handler; + $this->entityManager = $entity_manager; + $this->shortcutStorage = $shortcut_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + $entity_manager = $container->get('plugin.manager.entity'); + return new static( + $container->get('module_handler'), + $entity_manager, + $entity_manager->getStorageController('shortcut') + ); + } + + /** + * Returns a rendered edit form to create a new shortcut associated to the + * given shortcut set. + * + * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set + * The shortcut set this shortcut will be added to. + * + * @return array + * The shortcut add form. + */ + public function addForm(ShortcutSetInterface $shortcut_set) { + $shortcut = $this->shortcutStorage->create(array('set' => $shortcut_set->id())); + if ($this->moduleHandler->moduleExists('language')) { + $shortcut->langcode = language_get_default_langcode('shortcut', $shortcut_set->id()); + } + return $this->entityManager->getForm($shortcut, 'add'); + } + +} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php index a67b53b..15583ad 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php @@ -7,9 +7,10 @@ namespace Drupal\shortcut\Controller; +use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityManager; -use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Path\AliasManagerInterface; use Drupal\Core\Routing\PathBasedGeneratorInterface; use Drupal\shortcut\ShortcutSetInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -23,13 +24,6 @@ class ShortcutSetController implements ControllerInterface { /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** * Stores the entity manager. * * @var \Drupal\Core\Entity\EntityManager @@ -44,19 +38,36 @@ class ShortcutSetController implements ControllerInterface { protected $urlGenerator; /** + * The path alias manager. + * + * @var \Drupal\Core\Path\AliasManagerInterface + */ + protected $aliasManager; + + /** + * The entity query factory. + * + * @var \Drupal\Core\Entity\Query\QueryFactory + */ + protected $entityQueryFactory; + + /** * Constructs a new \Drupal\shortcut\Controller\ShortCutController object. * * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator * The URL generator. + * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager + * The path alias manager. + * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory + * The entity query factory. */ - public function __construct(EntityManager $entity_manager, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator) { + public function __construct(EntityManager $entity_manager, PathBasedGeneratorInterface $url_generator, AliasManagerInterface $alias_manager, QueryFactory $entity_query_factory) { $this->entityManager = $entity_manager; - $this->moduleHandler = $module_handler; $this->urlGenerator = $url_generator; + $this->aliasManager = $alias_manager; + $this->entityQueryFactory = $entity_query_factory; } /** @@ -65,8 +76,9 @@ public function __construct(EntityManager $entity_manager, ModuleHandlerInterfac public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.entity'), - $container->get('module_handler'), - $container->get('url_generator') + $container->get('url_generator'), + $container->get('path.alias_manager'), + $container->get('entity.query') ); } @@ -85,21 +97,33 @@ public static function create(ContainerInterface $container) { */ public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Request $request) { $token = $request->query->get('token'); - $link = $request->query->get('link'); - if (isset($token) && drupal_valid_token($token, 'shortcut-add-link') && shortcut_valid_link($link)) { - $item = menu_get_item($link); - $title = ($item && $item['title']) ? $item['title'] : $link; - $link = array( - 'link_title' => $title, - 'link_path' => $link, - ); - $this->moduleHandler->loadInclude('shortcut', 'admin.inc'); - shortcut_admin_add_link($link, $shortcut_set); - if ($shortcut_set->save() == SAVED_UPDATED) { - drupal_set_message(t('Added a shortcut for %title.', array('%title' => $link['link_title']))); + $link_path = $request->query->get('link'); + if (isset($token) && drupal_valid_token($token, 'shortcut-add-link') && shortcut_valid_link($link_path)) { + // Normalize the path in case it is an alias. + $link_path = $this->aliasManager->getSystemPath($link_path); + if (empty($link_path)) { + $link_path = ''; + } + + $result = $this->entityQueryFactory->get('menu_link') + ->condition('link_path', $link_path, '=') + ->execute(); + + if (!empty($result)) { + $menu_link = $this->entityManager->getStorageController('menu_link')->load(reset($result)); + + $shortcut = $this->entityManager->getStorageController('shortcut')->create(array( + 'title' => $menu_link->label(), + 'menu_link' => $menu_link, + )); + $shortcut->save(); + + $shortcut_set->addShortcut($shortcut)->save(); + + drupal_set_message(t('Added a shortcut for %title.', array('%title' => $menu_link->label()))); } else { - drupal_set_message(t('Unable to add a shortcut for %title.', array('%title' => $link['link_title']))); + drupal_set_message(t('Unable to add a shortcut for %path.', array('%path' => $link_path))); } return new RedirectResponse($this->urlGenerator->generateFromPath('', array('absolute' => TRUE))); } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php index 29da4a8..3413a24 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php @@ -35,6 +35,7 @@ public function form(array $form, array &$form_state) { ), ); + dsm($this->entity->links); foreach ($this->entity->links as $link) { $mlid = $link->id(); $form['shortcuts']['links'][$mlid]['#attributes']['class'][] = 'draggable'; diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php similarity index 60% rename from core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php rename to core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php index 9546e7d..19b3371 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php @@ -2,46 +2,47 @@ /** * @file - * Contains \Drupal\shortcut\Form\LinkDelete. + * Contains \Drupal\shortcut\Form\ShortcutDeleteForm. */ namespace Drupal\shortcut\Form; use Drupal\Core\Form\ConfirmFormBase; use Drupal\menu_link\Plugin\Core\Entity\MenuLink; +use Drupal\shortcut\ShortcutInterface; use Symfony\Component\HttpFoundation\Request; /** * Builds the shortcut link deletion form. */ -class LinkDelete extends ConfirmFormBase { +class ShortcutDeleteForm extends ConfirmFormBase { /** - * The menu link to delete. + * The shortcut to delete. * - * @var \Drupal\menu_link\Plugin\Core\Entity\MenuLink + * @var \Drupal\shortcut\ShortcutInterface */ - protected $menuLink; + protected $shortcut; /** * {@inheritdoc} */ public function getFormID() { - return 'shortcut_link_delete'; + return 'shortcut_delete'; } /** * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to delete the shortcut %title?', array('%title' => $this->menuLink->link_title)); + return t('Are you sure you want to delete the shortcut %title?', array('%title' => $this->shortcut->title)); } /** * {@inheritdoc} */ public function getCancelPath() { - return 'admin/config/user-interface/shortcut/manage/' . $this->menuLink->menu_name; + return 'admin/config/user-interface/shortcut/manage/' . $this->shortcut->bundle(); } /** @@ -54,8 +55,8 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, MenuLink $menu_link = NULL, Request $request = NULL) { - $this->menuLink = $menu_link; + public function buildForm(array $form, array &$form_state, ShortcutInterface $shortcut = NULL, Request $request = NULL) { + $this->shortcut = $shortcut; return parent::buildForm($form, $form_state, $request); } @@ -64,10 +65,9 @@ public function buildForm(array $form, array &$form_state, MenuLink $menu_link = * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - menu_link_delete($this->menuLink->mlid); - $set_name = str_replace('shortcut-', '' , $this->menuLink->menu_name); - $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $set_name; - drupal_set_message(t('The shortcut %title has been deleted.', array('%title' => $this->menuLink->link_title))); + $this->shortcut->delete(); + $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $this->shortcut->bundle(); + drupal_set_message(t('The shortcut %title has been deleted.', array('%title' => $this->shortcut->title))); } } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php new file mode 100644 index 0000000..d4b6549 --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php @@ -0,0 +1,101 @@ +id); + unset($this->uuid); + unset($this->shortcut_set); + unset($this->title); + unset($this->weight); + unset($this->menu_link); + } + +} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/ShortcutSet.php b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/ShortcutSet.php index d55c61b..a870a2c 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/ShortcutSet.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/ShortcutSet.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\shortcut\ShortcutInterface; use Drupal\shortcut\ShortcutSetInterface; /** @@ -86,22 +87,15 @@ public function uri() { * {@inheritdoc} */ public function postCreate(EntityStorageControllerInterface $storage_controller) { - // Generate menu-compatible set name. if (!$this->getOriginalID()) { // Save a new shortcut set with links copied from the user's default set. $default_set = shortcut_default_set(); - // Generate a name to have no collisions with menu. - // Size of menu_name is 32 so id could be 23 = 32 - strlen('shortcut-'). - $id = substr($this->id(), 0, 23); - $this->set('id', $id); - if ($default_set->id() != $id) { - foreach ($default_set->links as $link) { - $link = $link->createDuplicate(); - $link->enforceIsNew(); - $link->menu_name = $id; - $link->save(); - $this->links[$link->uuid()] = $link; - } + foreach ($default_set->links as $shortcut) { + $shortcut = $shortcut->createDuplicate(); + $shortcut->enforceIsNew(); + $shortcut->shortcut_set->value = $this->id(); + $shortcut->save(); + $this->links[$shortcut->uuid()] = $shortcut; } } } @@ -121,13 +115,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { */ public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) { foreach ($this->links as $uuid) { - if ($menu_link = entity_load_by_uuid('menu_link', $uuid)) { - // Do not specifically associate these links with the shortcut module, - // since other modules may make them editable via the menu system. - // However, we do need to specify the correct menu name. - $menu_link->menu_name = 'shortcut-' . $this->id(); - $menu_link->plid = 0; - $menu_link->save(); + if ($shortcut = entity_load_by_uuid('shortcut', $uuid)) { + $shortcut->save(); } } } @@ -138,9 +127,36 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) { foreach ($entities as $entity) { $storage_controller->deleteAssignedShortcutSets($entity); - // Next, delete the menu links for this set. - menu_delete_links('shortcut-' . $entity->id()); + // Next, delete the shortcuts for this set. + $shortcut_ids = \Drupal::entityQuery('shortcut') + ->condition('set', $entity->id(), '=') + ->execute(); + $controller = \Drupal::entityManager()->getStorageController('shortcut'); + $entities = $controller->loadMultiple($shortcut_ids); + $controller->delete($entities); } } + + /** + * {@inheritdoc} + */ + public function addShortcut(ShortcutInterface $shortcut) { + $this->links[$shortcut->uuid()] = $shortcut; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function resetLinkWeights() { + $weight = -50; + foreach ($this->links as $link) { + $link->weight->value = ++$weight; + } + + return $this; + } + } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php new file mode 100644 index 0000000..29350ea --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php @@ -0,0 +1,37 @@ +bundle())) { + return shortcut_set_edit_access($shortcut_set, $account); + } + } + + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + if ($shortcut_set = shortcut_set_load($entity_bundle)) { + return shortcut_set_edit_access($shortcut_set, $account); + } + } + +} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php new file mode 100644 index 0000000..3dcb432 --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php @@ -0,0 +1,180 @@ +aliasManager = $alias_manager; + $this->storageController = $storage_controller; + $this->entityQueryFactory = $entity_query_factory; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('module_handler'), + $container->get('path.alias_manager'), + $container->get('plugin.manager.entity')->getStorageController($entity_type), + $container->get('entity.query') + ); + } + + /** + * {@inheritdoc} + */ + public function form(array $form, array &$form_state) { + $form = parent::form($form, $form_state); + $entity = $this->entity; + + $form['title'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#default_value' => $entity->title->value, + '#size' => 40, + '#maxlength' => 255, + '#required' => TRUE, + '#weight' => -10, + ); + + $form['link_path'] = array( + '#type' => 'textfield', + '#title' => t('Path'), + '#size' => 40, + '#maxlength' => 255, + '#field_prefix' => url(NULL, array('absolute' => TRUE)), + '#default_value' => (!$entity->isNew()) ? $entity->menu_link->entity->link_path : NULL, + ); + + $form['langcode'] = array( + '#title' => t('Language'), + '#type' => 'language_select', + '#default_value' => $entity->getUntranslated()->language()->id, + '#languages' => Language::STATE_ALL, + ); + + $form['shortcut_set'] = array( + '#type' => 'value', + '#value' => $entity->bundle(), + ); + + $form['menu_link'] = array( + '#type' => 'value', + '#value' => $entity->menu_link->target_id, + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validate(array $form, array &$form_state) { + if (!shortcut_valid_link($form_state['values']['link_path'])) { + form_set_error('link_path', t('The link must correspond to a valid path on the site.')); + } + else { + // Normalize the path in case it is an alias. + $link_path = $this->aliasManager->getSystemPath($form_state['values']['link_path']); + if (empty($link_path)) { + $link_path = ''; + } + + $result = $this->entityQueryFactory->get('menu_link') + ->condition('link_path', $link_path, '=') + ->execute(); + + if (!empty($result)) { + form_set_value($form['menu_link'], reset($result), $form_state); + } + else { + form_set_error('link_path', t('A menu link corresponding to this path was not found.')); + } + } + + parent::validate($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, array &$form_state) { + $entity = $this->entity; + $entity->save(); + + if ($entity->isNew()) { + $shortcut_set = $this->storageController->load($entity->bundle()); + $shortcut_set->addShortcut($entity)->save(); + + $message = t('The shortcut %link has been updated.', array('%link' => $entity->title->value)); + } + else { + $message = t('Added a shortcut for %title.', array('%title' => $entity->title->value)); + } + drupal_set_message($message); + + $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $entity->bundle(); + } + + /** + * {@inheritdoc} + */ + public function delete(array $form, array &$form_state) { + $form_state['redirect'] = array('admin/config/user-interface/shortcut/link/' . $this->entity->id() . '/delete'); + } + +} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php new file mode 100644 index 0000000..ecc29fc --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php @@ -0,0 +1,17 @@ + $entity) { - $links = menu_load_links('shortcut-' . $id); - foreach ($links as $menu_link) { - $entity->links[$menu_link->uuid()] = $menu_link; + $shortcuts = $this->entityManager->getStorageController('shortcut')->loadByProperties(array('shortcut_set' => $id)); + foreach ($shortcuts as $shortcut) { + $entity->links[$shortcut->uuid()] = $shortcut; } } } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutStorageController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutStorageController.php new file mode 100644 index 0000000..88632eb --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutStorageController.php @@ -0,0 +1,69 @@ + t('ID'), + 'description' => t('The ID of the shortcut.'), + 'type' => 'integer_field', + 'read-only' => TRUE, + ); + $fields['uuid'] = array( + 'label' => t('UUID'), + 'description' => t('The UUID of the shortcut.'), + 'type' => 'uuid_field', + ); + $fields['shortcut_set'] = array( + 'label' => t('Shortcut set'), + 'description' => t('The bundle of the shortcut.'), + 'type' => 'string_field', + 'required' => TRUE, + ); + $fields['title'] = array( + 'label' => t('Title'), + 'description' => t('The name of the shortcut.'), + 'type' => 'string_field', + 'translatable' => TRUE, + ); + $fields['weight'] = array( + 'label' => t('Weight'), + 'description' => t('Weight among shortcuts in the same shortcut set.'), + 'type' => 'integer_field', + ); + $fields['menu_link'] = array( + 'label' => t('Menu link'), + 'description' => t('The referenced menu link.'), + 'type' => 'entity_reference_field', + 'settings' => array('target_type' => 'menu_link'), + 'required' => TRUE, + ); + $fields['langcode'] = array( + 'label' => t('Language code'), + 'description' => t('The language code of the shortcut.'), + 'type' => 'language_field', + ); + $fields['default_langcode'] = array( + 'label' => t('Default language'), + 'description' => t('Flag to indicate whether this is the default language.'), + 'type' => 'boolean_field', + ); + return $fields; + } + +} diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc index b406787..928a1ad 100644 --- a/core/modules/shortcut/shortcut.admin.inc +++ b/core/modules/shortcut/shortcut.admin.inc @@ -5,8 +5,8 @@ * Administrative page callbacks for the shortcut module. */ -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Drupal\shortcut\ShortcutInterface; +use Drupal\shortcut\ShortcutSetInterface; /** * Form callback: builds the form for switching shortcut sets. @@ -171,177 +171,166 @@ function shortcut_set_switch_submit($form, &$form_state) { shortcut_set_assign_user($set, $account); } -/** - * Form callback: builds the form for adding a new shortcut link. - * - * @param $form - * An associative array containing the structure of the form. - * @param $form_state - * An associative array containing the current state of the form. - * @param $shortcut_set Drupal\shortcut\Plugin\Core\Entity\Shortcut - * An object representing the shortcut set to which the link will be added. - * - * @return - * An array representing the form definition. - * - * @ingroup forms - * @see shortcut_link_edit_validate() - * @see shortcut_link_add_submit() - */ -function shortcut_link_add($form, &$form_state, $shortcut_set) { - drupal_set_title(t('Add new shortcut')); - $form['shortcut_set'] = array( - '#type' => 'value', - '#value' => $shortcut_set, - ); - $form += _shortcut_link_form_elements(); - return $form; -} - -/** - * Form callback: builds the form for editing a shortcut link. - * - * @param $form - * An associative array containing the structure of the form. - * @param $form_state - * An associative array containing the current state of the form. - * @param $shortcut_link - * An array representing the link that is being edited. - * - * @return - * An array representing the form definition. - * - * @ingroup forms - * @see shortcut_link_edit_validate() - * @see shortcut_link_edit_submit() - */ -function shortcut_link_edit($form, &$form_state, $shortcut_link) { - drupal_set_title(t('Editing @shortcut', array('@shortcut' => $shortcut_link['link_title']))); - $form['original_shortcut_link'] = array( - '#type' => 'value', - '#value' => $shortcut_link, - ); - $form += _shortcut_link_form_elements($shortcut_link); - return $form; -} - -/** - * Helper function for building a form for adding or editing shortcut links. - * - * @param $shortcut_link - * (optional) An array representing the shortcut link that will be edited. If - * not provided, a new link will be created. - * - * @return - * An array of form elements. - */ -function _shortcut_link_form_elements($shortcut_link = NULL) { - if (!isset($shortcut_link)) { - $shortcut_link = entity_create('menu_link', array( - 'link_title' => '', - 'link_path' => '' - )); - } - else { - $shortcut_link['link_path'] = ($shortcut_link['link_path'] == '') ? '' : Drupal::service('path.alias_manager')->getPathAlias($shortcut_link['link_path']); - } - - $form['shortcut_link']['#tree'] = TRUE; - $form['shortcut_link']['link_title'] = array( - '#type' => 'textfield', - '#title' => t('Name'), - '#size' => 40, - '#maxlength' => 255, - '#default_value' => $shortcut_link['link_title'], - '#required' => TRUE, - ); - - $form['shortcut_link']['link_path'] = array( - '#type' => 'textfield', - '#title' => t('Path'), - '#size' => 40, - '#maxlength' => 255, - '#field_prefix' => url(NULL, array('absolute' => TRUE)), - '#default_value' => $shortcut_link['link_path'], - ); - - $form['#validate'][] = 'shortcut_link_edit_validate'; - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Save'), - ); - - return $form; -} - -/** - * Validation handler for the shortcut link add and edit forms. - */ -function shortcut_link_edit_validate($form, &$form_state) { - if (!shortcut_valid_link($form_state['values']['shortcut_link']['link_path'])) { - form_set_error('shortcut_link][link_path', t('The link must correspond to a valid path on the site.')); - } -} - -/** - * Submit handler for shortcut_link_edit(). - */ -function shortcut_link_edit_submit($form, &$form_state) { - // Normalize the path in case it is an alias. - $shortcut_path = Drupal::service('path.alias_manager')->getSystemPath($form_state['values']['shortcut_link']['link_path']); - if (empty($shortcut_path)) { - $shortcut_path = ''; - } - $form_state['values']['shortcut_link']['link_path'] = $shortcut_path; - - $shortcut_link = $form_state['values']['original_shortcut_link']; - foreach ($form_state['values']['shortcut_link'] as $key => $value) { - $shortcut_link[$key] = $value; - } - - menu_link_save($shortcut_link); - $set_name = str_replace('shortcut-', '' , $shortcut_link['menu_name']); - $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $set_name; - drupal_set_message(t('The shortcut %link has been updated.', array('%link' => $shortcut_link['link_title']))); -} - -/** - * Submit handler for shortcut_link_add(). - */ -function shortcut_link_add_submit($form, &$form_state) { - // Add the shortcut link to the set. - $shortcut_set = $form_state['values']['shortcut_set']; - $shortcut_link = $form_state['values']['shortcut_link']; - $shortcut_link['menu_name'] = $shortcut_set->id(); - shortcut_admin_add_link($shortcut_link, $shortcut_set); - $shortcut_set->save(); - $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $shortcut_set->id(); - drupal_set_message(t('Added a shortcut for %title.', array('%title' => $shortcut_link['link_title']))); -} - -/** - * Adds a link to the end of a shortcut set, keeping within a prescribed limit. - * - * @param $link - * An array representing a shortcut link. - * @param $shortcut_set Drupal\shortcut\Plugin\Core\Entity\Shortcut - * An object representing the shortcut set which the link will be added to. - * The links in the shortcut set will be re-weighted so that the new link is - * at the end, and some existing links may be disabled (if the $limit - * parameter is provided). - */ -function shortcut_admin_add_link($shortcut_link, &$shortcut_set) { - // Normalize the path in case it is an alias. - $shortcut_link['link_path'] = Drupal::service('path.alias_manager')->getSystemPath($shortcut_link['link_path']); - if (empty($shortcut_link['link_path'])) { - $shortcut_link['link_path'] = ''; - } - $menu_link = entity_create('menu_link', $shortcut_link); - $menu_link->save(); - - // Add the link to the end of the list. - $shortcut_set->links[$menu_link->uuid()] = $menu_link; - shortcut_set_reset_link_weights($shortcut_set); -} +///** +// * Form callback: builds the form for adding a new shortcut link. +// * +// * @param array $form +// * An associative array containing the structure of the form. +// * @param array $form_state +// * An associative array containing the current state of the form. +// * @param Drupal\shortcut\ShortcutSetInterface $shortcut_set +// * An object representing the shortcut set to which the link will be added. +// * +// * @return array +// * An array representing the form definition. +// * +// * @ingroup forms +// * +// * @see \Drupal\shortcut\ShortcutFormController::save() +// */ +//function shortcut_link_add($form, &$form_state, ShortcutSetInterface $shortcut_set) { +// drupal_set_title(t('Add new shortcut')); +// +// $shortcut = entity_create('shortcut', array( +// 'shorcut_set' => $shortcut_set->id()) +// ); +// if (Drupal::moduleHandler()->moduleExists('language')) { +// $shortcut->langcode->value = language_get_default_langcode('shortcut', $shortcut_set->id()); +// } +// return Drupal::entityManager()->getForm($shortcut, 'add'); +//} +// +///** +// * Form callback: builds the form for editing a shortcut link. +// * +// * @param array $form +// * An associative array containing the structure of the form. +// * @param array $form_state +// * An associative array containing the current state of the form. +// * @param \Drupal\shortcut\ShortcutInterface $shortcut +// * An array representing the link that is being edited. +// * +// * @return array +// * An array representing the form definition. +// * +// * @ingroup forms +// * +// * @see \Drupal\shortcut\ShortcutFormController::save() +// */ +//function shortcut_link_edit(array $form, array &$form_state, ShortcutInterface $shortcut) { +// drupal_set_title(t('Editing @shortcut', array('@shortcut' => $shortcut['link_title']))); +// +// return Drupal::entityManager()->getForm($shortcut, 'edit'); +//} +// +///** +// * Helper function for building a form for adding or editing shortcut links. +// * +// * @param $shortcut_link +// * (optional) An array representing the shortcut link that will be edited. If +// * not provided, a new link will be created. +// * +// * @return +// * An array of form elements. +// */ +//function _shortcut_link_form_elements($shortcut_link = NULL) { +// if (!isset($shortcut_link)) { +// $shortcut_link = entity_create('menu_link', array( +// 'link_title' => '', +// 'link_path' => '' +// )); +// } +// else { +// $shortcut_link['link_path'] = ($shortcut_link['link_path'] == '') ? '' : Drupal::service('path.alias_manager')->getPathAlias($shortcut_link['link_path']); +// } +// +// $form['shortcut_link']['#tree'] = TRUE; +// $form['shortcut_link']['link_title'] = array( +// '#type' => 'textfield', +// '#title' => t('Name'), +// '#size' => 40, +// '#maxlength' => 255, +// '#default_value' => $shortcut_link['link_title'], +// '#required' => TRUE, +// ); +// +// $form['shortcut_link']['link_path'] = array( +// '#type' => 'textfield', +// '#title' => t('Path'), +// '#size' => 40, +// '#maxlength' => 255, +// '#field_prefix' => url(NULL, array('absolute' => TRUE)), +// '#default_value' => $shortcut_link['link_path'], +// ); +// +// $form['#validate'][] = 'shortcut_link_edit_validate'; +// +// $form['actions'] = array('#type' => 'actions'); +// $form['actions']['submit'] = array( +// '#type' => 'submit', +// '#value' => t('Save'), +// ); +// +// return $form; +//} +// +///** +// * Submit handler for shortcut_link_edit(). +// */ +//function shortcut_link_edit_submit($form, &$form_state) { +// // Normalize the path in case it is an alias. +// $shortcut_path = Drupal::service('path.alias_manager')->getSystemPath($form_state['values']['shortcut_link']['link_path']); +// if (empty($shortcut_path)) { +// $shortcut_path = ''; +// } +// $form_state['values']['shortcut_link']['link_path'] = $shortcut_path; +// +// $shortcut_link = $form_state['values']['original_shortcut_link']; +// foreach ($form_state['values']['shortcut_link'] as $key => $value) { +// $shortcut_link[$key] = $value; +// } +// +// menu_link_save($shortcut_link); +// $set_name = str_replace('shortcut-', '' , $shortcut_link['menu_name']); +// $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $set_name; +// drupal_set_message(t('The shortcut %link has been updated.', array('%link' => $shortcut_link['link_title']))); +//} +// +///** +// * Submit handler for shortcut_link_add(). +// */ +//function shortcut_link_add_submit($form, &$form_state) { +// // Add the shortcut link to the set. +// $shortcut_set = $form_state['values']['shortcut_set']; +// $shortcut_link = $form_state['values']['shortcut_link']; +// $shortcut_link['menu_name'] = $shortcut_set->id(); +// shortcut_admin_add_link($shortcut_link, $shortcut_set); +// $shortcut_set->save(); +// $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $shortcut_set->id(); +// drupal_set_message(t('Added a shortcut for %title.', array('%title' => $shortcut_link['link_title']))); +//} +// +///** +// * Adds a link to the end of a shortcut set, keeping within a prescribed limit. +// * +// * @param $link +// * An array representing a shortcut link. +// * @param $shortcut_set Drupal\shortcut\Plugin\Core\Entity\Shortcut +// * An object representing the shortcut set which the link will be added to. +// * The links in the shortcut set will be re-weighted so that the new link is +// * at the end, and some existing links may be disabled (if the $limit +// * parameter is provided). +// */ +//function shortcut_admin_add_link($shortcut_link, &$shortcut_set) { +// // Normalize the path in case it is an alias. +// $shortcut_link['link_path'] = Drupal::service('path.alias_manager')->getSystemPath($shortcut_link['link_path']); +// if (empty($shortcut_link['link_path'])) { +// $shortcut_link['link_path'] = ''; +// } +// $menu_link = entity_create('menu_link', $shortcut_link); +// $menu_link->save(); +// +// // Add the link to the end of the list. +// $shortcut_set->links[$menu_link->uuid()] = $menu_link; +// shortcut_set_reset_link_weights($shortcut_set); +//} diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index d78fa3b..ce70772 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -22,6 +22,98 @@ function shortcut_uninstall() { * Implements hook_schema(). */ function shortcut_schema() { + $schema['shortcut'] = array( + 'description' => 'Stores shortcut items.', + 'fields' => array( + 'id' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'description' => 'Primary Key: Unique shortcut ID.', + ), + 'uuid' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => FALSE, + 'description' => 'Unique Key: Universally unique identifier for this shortcut.', + ), + 'shortcut_set' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The bundle of the shortcut.', + ), + 'langcode' => array( + 'type' => 'varchar', + 'length' => 12, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The {language}.langcode of the original variant of this shortcut.', + ), + 'weight' => array( + 'description' => 'Weight among shortcuts in the same shortcut set.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'menu_link' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => NULL, + 'description' => 'The {menu_links}.mlid of the associated menu link.', + ), + ), + 'primary key' => array('id'), + 'unique keys' => array( + 'uuid' => array('uuid'), + ), + 'foreign keys' => array( + 'menu_links' => array( + 'table' => 'menu_links', + 'columns' => array('menu_link' => 'mlid'), + ), + ), + ); + + $schema['shortcut_property_data'] = array( + 'description' => 'Stores shortcut properties.', + 'fields' => array( + 'id' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'The {shortcut}.id of the shortcut.', + ), + 'langcode' => array( + 'type' => 'varchar', + 'length' => 12, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The {language}.langcode of this variant of this shortcut.', + ), + 'default_langcode' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 1, + 'description' => 'Boolean indicating whether the current variant is in the original entity language.', + ), + 'title' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => FALSE, + 'description' => 'The title of the shortcut.', + ), + ), + 'foreign keys' => array( + 'shortcut' => array( + 'table' => 'shortcut', + 'columns' => array('id' => 'id'), + ), + ), + 'primary key' => array('id', 'langcode'), + ); + $schema['shortcut_set_users'] = array( 'description' => 'Maps users to shortcut sets.', 'fields' => array( diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index c22c97f..24da7de 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -5,7 +5,9 @@ * Allows users to manage customizable lists of shortcut links. */ +use Drupal\Core\Session\AccountInterface; use Drupal\shortcut\Plugin\Core\Entity\Shortcut; +use Drupal\shortcut\ShortcutSetInterface; /** * Implements hook_help(). @@ -114,27 +116,31 @@ function shortcut_menu() { 'title' => 'Delete shortcut set', 'route_name' => 'shortcut_set_delete', ); - $items['admin/config/user-interface/shortcut/manage/%shortcut_set/add-link'] = array( - 'title' => 'Add shortcut', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('shortcut_link_add', 5), - 'access callback' => 'shortcut_set_edit_access', - 'access arguments' => array(5), - 'type' => MENU_LOCAL_ACTION, - 'file' => 'shortcut.admin.inc', - ); - $items['admin/config/user-interface/shortcut/link/%menu_link'] = array( - 'title' => 'Edit shortcut', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('shortcut_link_edit', 5), - 'access callback' => 'shortcut_link_access', - 'access arguments' => array(5), - 'file' => 'shortcut.admin.inc', - ); - $items['admin/config/user-interface/shortcut/link/%menu_link/delete'] = array( - 'title' => 'Delete shortcut', - 'route_name' => 'shortcut_link_delete', - ); +// $items['admin/config/user-interface/shortcut/manage/%shortcut_set/add-link'] = array( +// 'title' => 'Add shortcut', +// 'page callback' => 'drupal_get_form', +// 'page arguments' => array('shortcut_link_add', 5), +// 'access callback' => 'shortcut_set_edit_access', +// 'access arguments' => array(5), +// 'type' => MENU_LOCAL_ACTION, +// 'file' => 'shortcut.admin.inc', +// ); +// $items['admin/config/user-interface/shortcut/link/%menu_link'] = array( +// 'title' => 'Edit shortcut', +// 'page callback' => 'drupal_get_form', +// 'page arguments' => array('shortcut_link_edit', 5), +// 'access callback' => 'shortcut_link_access', +// 'access arguments' => array(5), +// 'file' => 'shortcut.admin.inc', +// ); +// $items['admin/config/user-interface/shortcut/link/{shortcut}'] = array( +// 'title' => 'Edit shortcut', +// 'route_name' => 'shortcut_edit', +// ); +// $items['admin/config/user-interface/shortcut/link/{shortcut}/delete'] = array( +// 'title' => 'Delete shortcut', +// 'route_name' => 'shortcut_delete', +// ); $items['user/%user/shortcuts'] = array( 'title' => 'Shortcuts', 'page callback' => 'drupal_get_form', @@ -161,22 +167,24 @@ function shortcut_admin_paths() { /** * Access callback for editing a shortcut set. * - * @param $shortcut_set Drupal\shortcut\Plugin\Core\Entity\Shortcut + * @param Drupal\shortcut\ShortcutSetInterface $shortcut_set * (optional) The shortcut set to be edited. If not set, the current user's * shortcut set will be used. + * @param \Drupal\Core\Session\AccountInterface $account + * (optional) The user for which to check access. * - * @return + * @return bool * TRUE if the current user has access to edit the shortcut set, FALSE * otherwise. */ -function shortcut_set_edit_access($shortcut_set = NULL) { +function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL, AccountInterface $account = NULL) { // Sufficiently-privileged users can edit their currently displayed shortcut // set, but not other sets. Shortcut administrators can edit any set. - if (user_access('administer shortcuts')) { + if (user_access('administer shortcuts', $account)) { return TRUE; } - if (user_access('customize shortcut links')) { - return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set(); + if (user_access('customize shortcut links', $account)) { + return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set($account); } return FALSE; } @@ -243,10 +251,10 @@ function shortcut_menu_link_delete($menu_link) { /** * Loads the data for a shortcut set. * - * @param $id + * @param string $id * The machine-name of the shortcut set to load. * - * @return object + * @return \Drupal\shortcut\ShortcutSetInterface * If the shortcut set exists, an object containing the following properties: * - 'id': The internal name of the shortcut set. * - 'label': The title of the shortcut set. @@ -471,7 +479,7 @@ function shortcut_preprocess_page(&$variables) { // Check if $link is already a shortcut and set $link_mode accordingly. foreach ($shortcut_set->links as $uuid => $shortcut) { - if ($link == $shortcut['link_path']) { + if ($link == $shortcut->menu_link->entity['link_path']) { $mlid = $shortcut['mlid']; break; } diff --git a/core/modules/shortcut/shortcut.routing.yml b/core/modules/shortcut/shortcut.routing.yml index faf495a..dc6127e 100644 --- a/core/modules/shortcut/shortcut.routing.yml +++ b/core/modules/shortcut/shortcut.routing.yml @@ -1,9 +1,23 @@ -shortcut_link_delete: - pattern: '/admin/config/user-interface/shortcut/link/{menu_link}/delete' +shortcut_add: + pattern: '/admin/config/user-interface/shortcut/manage/{shortcut_set}/add-link' defaults: - _form: 'Drupal\shortcut\Form\LinkDelete' + _content: '\Drupal\shortcut\Controller\ShortcutController::addForm' requirements: - _access_shortcut_link_delete: 'TRUE' + _access_shortcut_create: 'shortcut' + +shortcut_edit: + pattern: '/admin/config/user-interface/shortcut/link/{shortcut}' + defaults: + _entity_form: 'shortcut.default' + requirements: + _entity_access: 'shortcut.update' + +shortcut_delete: + pattern: '/admin/config/user-interface/shortcut/link/{shortcut}/delete' + defaults: + _entity_form: 'shortcut.delete' + requirements: + _entity_access: 'shortcut.delete' shortcut_set_delete: pattern: '/admin/config/user-interface/shortcut/manage/{shortcut_set}/delete' diff --git a/core/modules/shortcut/shortcut.services.yml b/core/modules/shortcut/shortcut.services.yml index bb95f49..2652c1e 100644 --- a/core/modules/shortcut/shortcut.services.yml +++ b/core/modules/shortcut/shortcut.services.yml @@ -1,5 +1,6 @@ services: - access_check.shortcut.link: - class: Drupal\shortcut\Access\LinkDeleteAccessCheck + access_check.shortcut.create: + class: Drupal\shortcut\Access\ShortcutCreateAccessCheck + arguments: ['@plugin.manager.entity'] tags: - { name: access_check } diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 5c29f4d..b2733e7 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -63,24 +63,39 @@ function standard_install() { user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access site-wide contact form')); // Populate the default shortcut set. - $shortcut_set = shortcut_set_load('default'); - $menu_link = entity_create('menu_link', array( - 'link_path' => 'node/add', - 'link_title' => t('Add content'), - 'weight' => -20, - )); - $menu_link->save(); - $shortcut_set->links[$menu_link->uuid()] = $menu_link; - - $menu_link = entity_create('menu_link', array( - 'link_path' => 'admin/content', - 'link_title' => t('All content'), - 'weight' => -19, - )); - $menu_link->save(); - $shortcut_set->links[$menu_link->uuid()] = $menu_link; - - $shortcut_set->save(); +// $shortcut_set = shortcut_set_load('default'); +// +// $result = Drupal::entityQuery('menu_link') +// ->condition('link_path', 'node/add', '=') +// ->execute(); +// +// if (!empty($result)) { +// $shortcut = entity_create('shortcut', array( +// 'set' => $shortcut_set->id(), +// 'title' => t('Add content'), +// 'weight' => -20, +// 'menu_link' => reset($result), +// )); +// $shortcut->save(); +// $shortcut_set->links[$shortcut->uuid()] = $shortcut; +// } +// +// $result = Drupal::entityQuery('menu_link') +// ->condition('link_path', 'admin/content', '=') +// ->execute(); +// +// if (!empty($result)) { +// $shortcut = entity_create('shortcut', array( +// 'set' => $shortcut_set->id(), +// 'title' => t('All content'), +// 'weight' => -19, +// 'menu_link' => reset($result), +// )); +// $shortcut->save(); +// $shortcut_set->links[$shortcut->uuid()] = $shortcut; +// } +// +// $shortcut_set->save(); // Enable the admin theme. theme_enable(array('seven'));