You are here

public function Client::getActiveXmpFields in Media: Acquia DAM 8

Get a list of metadata.

Return value

array A list of active xmp metadata fields.

File

src/Client.php, line 38

Class

Client
Overridden implementation of the cweagans php-webdam-client.

Namespace

Drupal\media_acquiadam

Code

public function getActiveXmpFields() {
  if (!is_null($this->activeXmpFields)) {
    return $this->activeXmpFields;
  }
  try {
    $this
      ->checkAuth();
  } catch (\Exception $x) {
    \Drupal::logger('media_acquiadam')
      ->error('Unable to authenticate to retrieve xmp field data.');
    $this->activeXmpFields = [];
    return $this->activeXmpFields;
  }
  try {
    $response = $this->client
      ->request('GET', $this->baseUrl . '/metadataschemas/xmp?full=1', [
      'headers' => $this
        ->getDefaultHeaders(),
    ]);
  } catch (\Exception $x) {
    \Drupal::logger('media_acquiadam')
      ->error('Unable to get xmp field data.');
    $this->activeXmpFields = [];
    return $this->activeXmpFields;
  }
  $response = json_decode((string) $response
    ->getBody());
  $this->activeXmpFields = [];
  foreach ($response->xmpschema as $field) {
    if ($field->status == 'active') {
      $this->activeXmpFields['xmp_' . strtolower($field->field)] = [
        'name' => $field->name,
        'label' => $field->label,
        'type' => $field->type,
      ];
    }
  }
  return $this->activeXmpFields;
}