You are here

public function Key::postSave in Key 8

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 EntityBase::postSave

File

src/Entity/Key.php, line 335

Class

Key
Defines the Key entity.

Namespace

Drupal\key\Entity

Code

public function postSave(EntityStorageInterface $storage, $update = TRUE) {

  // Allow the key provider to perform post-save actions.
  $this
    ->getKeyProvider()
    ->postSave($this, $storage, $update);

  // If an original key exists.
  if (isset($this->original)) {

    /* @var $original \Drupal\key\Entity\Key */
    $original = $this->original;

    // If the original key's provider allows setting a key value and
    // the plugin ID is different from the one that was just saved with
    // the entity.
    if ($original
      ->getKeyProvider() instanceof KeyProviderSettableValueInterface && $original
      ->getKeyProvider()
      ->getPluginId() != $this
      ->getKeyProvider()
      ->getPluginId()) {

      // Allow the original key's provider to delete the key value.
      $original
        ->deleteKeyValue();
    }
  }
  parent::postSave($storage, $update);
}