class ShortcutSet
Same name in this branch
- 10 core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet
Same name in other branches
- 9 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet
- 9 core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet
- 8.9.x core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet
- 8.9.x core/modules/shortcut/src/Plugin/migrate/source/d7/ShortcutSet.php \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet
- 11.x core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet
- 11.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
- class \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Entity\EntityInterface uses \Drupal\Core\Cache\RefinableCacheableDependencyTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityBase extends \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Config\Entity\ConfigEntityInterface uses \Drupal\Core\Plugin\PluginDependencyTrait, \Drupal\Core\Entity\SynchronizableEntityTrait
- class \Drupal\Core\Config\Entity\ConfigEntityBundleBase extends \Drupal\Core\Config\Entity\ConfigEntityBase
- class \Drupal\shortcut\Entity\ShortcutSet extends \Drupal\Core\Config\Entity\ConfigEntityBundleBase implements \Drupal\shortcut\ShortcutSetInterface
- class \Drupal\Core\Config\Entity\ConfigEntityBundleBase extends \Drupal\Core\Config\Entity\ConfigEntityBase
- class \Drupal\Core\Config\Entity\ConfigEntityBase extends \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Config\Entity\ConfigEntityInterface uses \Drupal\Core\Plugin\PluginDependencyTrait, \Drupal\Core\Entity\SynchronizableEntityTrait
Expanded class hierarchy of ShortcutSet
13 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 - NavigationShortcutsBlockTest.php in core/
modules/ navigation/ tests/ src/ Functional/ NavigationShortcutsBlockTest.php - ShortcutCacheTagsTest.php in core/
modules/ shortcut/ tests/ src/ Functional/ ShortcutCacheTagsTest.php - ShortcutLinksTest.php in core/
modules/ shortcut/ tests/ src/ Functional/ ShortcutLinksTest.php
File
-
core/
modules/ shortcut/ src/ Entity/ ShortcutSet.php, line 52
Namespace
Drupal\shortcut\EntityView 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 = $storage->getDefaultSet(\Drupal::currentUser());
// 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;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.