You are here

public function ShortcutSet::postSave in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet::postSave()
  2. 9 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet::postSave()

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides ConfigEntityBundleBase::postSave

File

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

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