3 namespace Drupal\shortcut\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\shortcut\ShortcutSetInterface;
10 * Defines the Shortcut set configuration entity.
13 * id = "shortcut_set",
14 * label = @Translation("Shortcut set"),
16 * "storage" = "Drupal\shortcut\ShortcutSetStorage",
17 * "access" = "Drupal\shortcut\ShortcutSetAccessControlHandler",
18 * "list_builder" = "Drupal\shortcut\ShortcutSetListBuilder",
20 * "default" = "Drupal\shortcut\ShortcutSetForm",
21 * "add" = "Drupal\shortcut\ShortcutSetForm",
22 * "edit" = "Drupal\shortcut\ShortcutSetForm",
23 * "customize" = "Drupal\shortcut\Form\SetCustomize",
24 * "delete" = "Drupal\shortcut\Form\ShortcutSetDeleteForm"
27 * config_prefix = "set",
28 * bundle_of = "shortcut",
34 * "customize-form" = "/admin/config/user-interface/shortcut/manage/{shortcut_set}/customize",
35 * "delete-form" = "/admin/config/user-interface/shortcut/manage/{shortcut_set}/delete",
36 * "edit-form" = "/admin/config/user-interface/shortcut/manage/{shortcut_set}",
37 * "collection" = "/admin/config/user-interface/shortcut",
45 class ShortcutSet extends ConfigEntityBundleBase implements ShortcutSetInterface {
48 * The machine name for the configuration entity.
55 * The human-readable name of the configuration entity.
64 public function postSave(EntityStorageInterface $storage, $update = TRUE) {
65 parent::postSave($storage, $update);
67 if (!$update && !$this->isSyncing()) {
68 // Save a new shortcut set with links copied from the user's default set.
69 $default_set = shortcut_default_set();
70 // This is the default set, do not copy shortcuts.
71 if ($default_set->id() != $this->id()) {
72 foreach ($default_set->getShortcuts() as $shortcut) {
73 $shortcut = $shortcut->createDuplicate();
74 $shortcut->enforceIsNew();
75 $shortcut->shortcut_set->target_id = $this->id();
85 public static function preDelete(EntityStorageInterface $storage, array $entities) {
86 parent::preDelete($storage, $entities);
88 foreach ($entities as $entity) {
89 $storage->deleteAssignedShortcutSets($entity);
91 // Next, delete the shortcuts for this set.
92 $shortcut_ids = \Drupal::entityQuery('shortcut')
93 ->condition('shortcut_set', $entity->id(), '=')
96 $controller = \Drupal::entityManager()->getStorage('shortcut');
97 $entities = $controller->loadMultiple($shortcut_ids);
98 $controller->delete($entities);
105 public function resetLinkWeights() {
107 foreach ($this->getShortcuts() as $shortcut) {
108 $shortcut->setWeight(++$weight);
118 public function getShortcuts() {
119 $shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(['shortcut_set' => $this->id()]);
120 uasort($shortcuts, ['\Drupal\shortcut\Entity\Shortcut', 'sort']);