You are here

public function AcquiadamUsageSubscriber::mediaUsageChange in Media: Acquia DAM 8

This method is called whenever an EntityUsage event is dispatched.

Parameters

\Drupal\entity_usage\Events\EntityUsageEvent $event: The event being triggered.

File

modules/media_acquiadam_report/src/EventSubscriber/AcquiadamUsageSubscriber.php, line 49

Class

AcquiadamUsageSubscriber
Subscribe to EntityUsage events.

Namespace

Drupal\media_acquiadam_report\EventSubscriber

Code

public function mediaUsageChange(EntityUsageEvent $event) {
  if ($event
    ->getTargetEntityType() == 'media') {
    $mid = $event
      ->getTargetEntityId();
    $asset_id_fields = media_acquiadam_get_bundle_asset_id_fields();
    $media = $this->entityTypeManager
      ->getStorage('media')
      ->load($mid);
    $media_bundle = $media
      ->bundle();

    // Clear cache tag on asset listing so entity usage count is up to date.
    if (array_key_exists($media_bundle, $asset_id_fields)) {
      Cache::invalidateTags([
        'config:views.view.acquia_dam_reporting',
      ]);
    }
  }
}