class ShortcutSet

Same name in this branch
  1. 9 core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet
Same name and namespace in other branches
  1. 11.x core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet
  2. 11.x core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet
  3. 10 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet
  4. 10 core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet
  5. 8.9.x core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet
  6. 8.9.x core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet

Defines the Shortcut set configuration entity.

Plugin annotation


@ConfigEntityType(
  id = "shortcut_set",
  label = @Translation("Shortcut set"),
  label_collection = @Translation("Shortcut sets"),
  label_singular = @Translation("shortcut set"),
  label_plural = @Translation("shortcut sets"),
  label_count = @PluralTranslation(
    singular = "@count shortcut set",
    plural = "@count shortcut sets",
  ),
  handlers = {
    "storage" = "Drupal\shortcut\ShortcutSetStorage",
    "access" = "Drupal\shortcut\ShortcutSetAccessControlHandler",
    "list_builder" = "Drupal\shortcut\ShortcutSetListBuilder",
    "form" = {
      "default" = "Drupal\shortcut\ShortcutSetForm",
      "add" = "Drupal\shortcut\ShortcutSetForm",
      "edit" = "Drupal\shortcut\ShortcutSetForm",
      "customize" = "Drupal\shortcut\Form\SetCustomize",
      "delete" = "Drupal\shortcut\Form\ShortcutSetDeleteForm"
    }
  },
  config_prefix = "set",
  bundle_of = "shortcut",
  entity_keys = {
    "id" = "id",
    "label" = "label"
  },
  links = {
    "customize-form" = "/admin/config/user-interface/shortcut/manage/{shortcut_set}/customize",
    "delete-form" = "/admin/config/user-interface/shortcut/manage/{shortcut_set}/delete",
    "edit-form" = "/admin/config/user-interface/shortcut/manage/{shortcut_set}",
    "collection" = "/admin/config/user-interface/shortcut",
  },
  config_export = {
    "id",
    "label",
  }
)

Hierarchy

Expanded class hierarchy of ShortcutSet

11 files declare their use of ShortcutSet
ConfigTranslationListUiTest.php in core/modules/config_translation/tests/src/Functional/ConfigTranslationListUiTest.php
MigrateShortcutSetTest.php in core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetTest.php
shortcut.module in core/modules/shortcut/shortcut.module
Allows users to manage customizable lists of shortcut links.
ShortcutLinksTest.php in core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
ShortcutResourceTestBase.php in core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php

... See full list

File

core/modules/shortcut/src/Entity/ShortcutSet.php, line 52

Namespace

Drupal\shortcut\Entity
View source
class ShortcutSet extends ConfigEntityBundleBase implements ShortcutSetInterface {
  
  /**
   * The machine name for the configuration entity.
   *
   * @var string
   */
  protected $id;
  
  /**
   * The human-readable name of the configuration entity.
   *
   * @var string
   */
  protected $label;
  
  /**
   * {@inheritdoc}
   */
  public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    parent::postSave($storage, $update);
    if (!$update && !$this->isSyncing()) {
      // Save a new shortcut set with links copied from the user's default set.
      $default_set = shortcut_default_set();
      // This is the default set, do not copy shortcuts.
      if ($default_set->id() != $this->id()) {
        foreach ($default_set->getShortcuts() as $shortcut) {
          $shortcut = $shortcut->createDuplicate();
          $shortcut->enforceIsNew();
          $shortcut->shortcut_set->target_id = $this->id();
          $shortcut->save();
        }
      }
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage, $entities);
    foreach ($entities as $entity) {
      $storage->deleteAssignedShortcutSets($entity);
      // Next, delete the shortcuts for this set.
      $shortcut_ids = \Drupal::entityQuery('shortcut')->accessCheck(FALSE)
        ->condition('shortcut_set', $entity->id(), '=')
        ->execute();
      $controller = \Drupal::entityTypeManager()->getStorage('shortcut');
      $entities = $controller->loadMultiple($shortcut_ids);
      $controller->delete($entities);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function resetLinkWeights() {
    $weight = -50;
    foreach ($this->getShortcuts() as $shortcut) {
      $shortcut->setWeight(++$weight);
      $shortcut->save();
    }
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getShortcuts() {
    $shortcuts = \Drupal::entityTypeManager()->getStorage('shortcut')
      ->loadByProperties([
      'shortcut_set' => $this->id(),
    ]);
    uasort($shortcuts, [
      '\\Drupal\\shortcut\\Entity\\Shortcut',
      'sort',
    ]);
    return $shortcuts;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.