You are here

public function EckEntityType::postSave in Entity Construction Kit (ECK) 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/EckEntityType.php, line 103

Class

EckEntityType
Defines the ECK Entity Type config entities.

Namespace

Drupal\eck\Entity

Code

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

  // Clear the router cache to prevent RouteNotFoundException while creating
  // the edit link.
  \Drupal::service('router.builder')
    ->rebuild();
  $edit_link = $this
    ->toLink($this
    ->t('Edit entity type'), 'edit-form')
    ->toString();
  if ($update) {
    $this
      ->logger($this
      ->id())
      ->notice('Entity type %label has been updated.', [
      '%label' => $this
        ->label(),
      'link' => $edit_link,
    ]);
  }
  else {
    $this
      ->logger($this
      ->id())
      ->notice('Entity type %label has been added.', [
      '%label' => $this
        ->label(),
      'link' => $edit_link,
    ]);
  }
  \Drupal::service('eck.entity.entity_update_service')
    ->applyUpdates($this
    ->id());
}