You are here

public static function Mapping::postDelete in GatherContent 8.5

Acts on deleted entities before the delete hook is invoked.

Used after the entities are deleted but before invoking the delete hook.

Parameters

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

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides EntityBase::postDelete

File

src/Entity/Mapping.php, line 332

Class

Mapping
Defines the GatherContent Mapping entity.

Namespace

Drupal\gathercontent\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $entities) {
  parent::postDelete($storage, $entities);

  // Delete the related migration definitions.
  $entityTypeManager = \Drupal::service('entity_type.manager');
  $migrationStorage = $entityTypeManager
    ->getStorage('migration');
  foreach ($entities as $entity) {
    $migrationIds = $entity
      ->getMigrations();
    if (!$migrationIds) {
      continue;
    }
    foreach ($migrationIds as $migrationId) {

      /** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */
      $migration = $migrationStorage
        ->load($migrationId);
      $migration
        ->delete();
    }
  }
}