You are here

public function UsageEventSubscriber::onDelete in Bynder 8

Removes usage from Bynder asset.

Parameters

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

File

src/EventSubscriber/UsageEventSubscriber.php, line 145

Class

UsageEventSubscriber
Listens for the usage events from Entity Usage module.

Namespace

Drupal\bynder\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) {
      (new UnableToDeleteUsageException($e
        ->getMessage()))
        ->logException()
        ->displayMessage();
    }
  }
}