You are here

public function UsageEventSubscriber::onDelete in Bynder 8.2

Removes usage from Bynder asset.

Parameters

\Drupal\entity_usage\Events\EntityUsageEvent $event: The event to process.

File

modules/bynder_usage/src/EventSubscriber/UsageEventSubscriber.php, line 148

Class

UsageEventSubscriber
Listens for the usage events from Entity Usage module.

Namespace

Drupal\bynder_usage\EventSubscriber

Code

public function onDelete(EntityUsageEvent $event) {
  $mediaInfo = $this
    ->getUsageEventMediainformation($event);
  if (isset($mediaInfo['mediaId'])) {
    try {
      $this->bynderApi
        ->removeAssetUsage($mediaInfo['mediaId'], $mediaInfo['url']);
    } catch (RequestException $e) {
      watchdog_exception('bynder', $e);
      (new UnableToDeleteUsageException($e
        ->getMessage()))
        ->logException()
        ->displayMessage();
    }
  }
}