You are here

public static function BrightcoveVideo::getProfileAllowedValues in Brightcove Video Connect 8.2

Same name and namespace in other branches
  1. 8 src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo::getProfileAllowedValues()
  2. 3.x src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo::getProfileAllowedValues()

Gets the allowed values for video profile.

Parameters

string $api_client: The API Client ID.

Return value

array The list of profiles.

3 calls to BrightcoveVideo::getProfileAllowedValues()
BrightcoveVideo::profileAllowedValues in src/Entity/BrightcoveVideo.php
Implements callback_allowed_values_function().
BrightcoveVideo::save in src/Entity/BrightcoveVideo.php
BrightcoveVideoForm::buildForm in src/Form/BrightcoveVideoForm.php
Form constructor.

File

src/Entity/BrightcoveVideo.php, line 1662

Class

BrightcoveVideo
Defines the Brightcove Video entity.

Namespace

Drupal\brightcove\Entity

Code

public static function getProfileAllowedValues($api_client) {
  $profiles = [];
  if (!empty($api_client)) {
    $cid = 'brightcove:video:profiles:' . $api_client;

    // If we have a hit in the cache, return the results.
    if ($cache = \Drupal::cache()
      ->get($cid)) {
      $profiles = $cache->data;
    }
    else {

      /** @var \Drupal\brightcove\Entity\BrightcoveAPIClient $api_client_entity */
      $api_client_entity = BrightcoveAPIClient::load($api_client);
      try {
        if (!is_null($api_client_entity)) {
          $client = $api_client_entity
            ->getClient();
          $json = $client
            ->request('GET', 1, 'ingestion', $api_client_entity
            ->getAccountId(), '/profiles', NULL);
          foreach ($json as $profile) {
            $profiles[$profile['id']] = $profile['name'];
          }

          // Order profiles by value.
          asort($profiles);

          // Save the results to cache.
          \Drupal::cache()
            ->set($cid, $profiles);
        }
        else {
          $profiles[] = t('Error: unable to fetch the list');
        }
      } catch (APIException $exception) {
        $profiles[] = t('Error: unable to fetch the list');
        watchdog_exception('brightcove', $exception);
      }
    }
  }
  return $profiles;
}