You are here

public static function Feed::postDelete in Feeds 8.3

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/Feed.php, line 549

Class

Feed
Defines the feed entity class.

Namespace

Drupal\feeds\Entity

Code

public static function postDelete(EntityStorageInterface $storage_controller, array $feeds) {

  // Delete values from other tables also referencing these feeds.
  $ids = array_keys($feeds);

  // Group feeds by type.
  $grouped = [];
  foreach ($feeds as $fid => $feed) {
    $grouped[$feed
      ->bundle()][$fid] = $feed;
  }

  // Alert plugins that we are deleting.
  foreach ($grouped as $group) {

    // Grab the first feed to get its type.
    $feed = reset($group);
    try {
      foreach ($feed
        ->getType()
        ->getPlugins() as $plugin) {
        $plugin
          ->onFeedDeleteMultiple($group);
      }
    } catch (EntityStorageException $e) {

      // Ignore the case where the feed type no longer exists, but do log an
      // error.
      $args = [
        '%title' => $feed
          ->label(),
        '@error' => $e
          ->getMessage(),
      ];
      \Drupal::logger('feeds')
        ->warning('Could not perform some post cleanups for feed %title because of the following error: @error', $args);
    }
  }

  // Clean up references in feeds_clean_list table for each feed.
  \Drupal::database()
    ->delete(CleanState::TABLE_NAME)
    ->condition('feed_id', $ids, 'IN')
    ->execute();
  \Drupal::service('event_dispatcher')
    ->dispatch(FeedsEvents::FEEDS_DELETE, new DeleteFeedsEvent($feeds));
}