public function UsageEventSubscriber::onAdd in Bynder 8
Adds usage for Bynder asset.
Parameters
\Drupal\entity_usage\Events\EntityUsageEvent $event: The event to process.
File
- src/
EventSubscriber/ UsageEventSubscriber.php, line 120
Class
- UsageEventSubscriber
- Listens for the usage events from Entity Usage module.
Namespace
Drupal\bynder\EventSubscriberCode
public function onAdd(EntityUsageEvent $event) {
if (\Drupal::service('module_handler')
->moduleExists('entity_usage')) {
$mediaInfo = $this
->getUsageEventMediainformation($event);
if (isset($mediaInfo)) {
try {
$this->bynderApi
->addAssetUsage($mediaInfo['mediaId'], $mediaInfo['url'], date(DATE_ISO8601, \Drupal::time()
->getRequestTime()), 'Added asset by user ' . \Drupal::currentUser()
->getAccountName() . '.');
} catch (RequestException $e) {
(new UnableToAddUsageException($e
->getMessage()))
->logException()
->displayMessage();
}
}
}
}