You are here

protected function TeamInvitationStorage::invokeHook in Apigee Edge 8

Invokes a hook on behalf of the entity.

Parameters

string $hook: One of 'create', 'presave', 'insert', 'update', 'predelete', 'delete', or 'revision_delete'.

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

Overrides ContentEntityStorageBase::invokeHook

File

modules/apigee_edge_teams/src/Entity/Storage/TeamInvitationStorage.php, line 110

Class

TeamInvitationStorage
Storage handler for team_invitation.

Namespace

Drupal\apigee_edge_teams\Entity\Storage

Code

protected function invokeHook($hook, EntityInterface $entity) {

  /** @var \Drupal\apigee_edge_teams\Entity\TeamInvitationInterface $entity */
  parent::invokeHook($hook, $entity);
  switch ($hook) {
    case 'insert':
      $this->eventDispatcher
        ->dispatch(TeamInvitationEvents::CREATED, new TeamInvitationEvent($entity));
      break;
    case 'update':

      /** @var \Drupal\apigee_edge_teams\Entity\TeamInvitationInterface $original */
      $original = $entity->original;
      if (!$original) {
        return;
      }

      // Do not persist original after events are fired.
      // @see https://www.drupal.org/project/drupal/issues/2140179.
      unset($entity->original);
      if (!$original
        ->isDeclined() && $entity
        ->isDeclined()) {
        $this->eventDispatcher
          ->dispatch(TeamInvitationEvents::DECLINED, new TeamInvitationEvent($entity));
      }
      if (!$original
        ->isAccepted() && $entity
        ->isAccepted()) {
        $this->eventDispatcher
          ->dispatch(TeamInvitationEvents::ACCEPTED, new TeamInvitationEvent($entity));
      }
      break;
  }
}