You are here

protected function UsageEventSubscriber::hasRemoteUsageByUri in Bynder 8.3

Same name and namespace in other branches
  1. 4.0.x modules/bynder_usage/src/EventSubscriber/UsageEventSubscriber.php \Drupal\bynder_usage\EventSubscriber\UsageEventSubscriber::hasRemoteUsageByUri()

Returns whether the given remote ID and URI have a remote usage.

Parameters

string $remote_id: The remote ID.

string $uri: The URI this asset was used on.

Return value

bool TRUE if there is a remote usage for the ID and URI. Otherwise, FALSE.

1 call to UsageEventSubscriber::hasRemoteUsageByUri()
UsageEventSubscriber::onUsageRegister in modules/bynder_usage/src/EventSubscriber/UsageEventSubscriber.php
Triggers when a usage is registered (create or update) for a Bynder asset.

File

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

Class

UsageEventSubscriber
Listens for the usage events from Entity Usage module.

Namespace

Drupal\bynder_usage\EventSubscriber

Code

protected function hasRemoteUsageByUri($remote_id, $uri) {
  $usages = $this->bynderApi
    ->getAssetUsages($remote_id);

  // No remote usages.
  if (empty($usages)) {
    return FALSE;
  }
  foreach ($usages as $usage) {

    // There is a remote usage on the given URI.
    if ($usage['uri'] === $uri) {
      return TRUE;
    }
  }
  return FALSE;
}