function ShortcutSet::postSave

Same name in other branches
  1. 9 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet::postSave()
  2. 8.9.x core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet::postSave()
  3. 10 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet::postSave()

Overrides ConfigEntityBundleBase::postSave

File

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

Class

ShortcutSet
Defines the Shortcut set configuration entity.

Namespace

Drupal\shortcut\Entity

Code

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();
            }
        }
    }
}

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