You are here

protected function MediaEntityHelper::getFieldPropertyValue in Media: Acquia DAM 8

Gets the value of a field without knowing the key to use.

Parameters

string $fieldName: The field name.

Return value

null|mixed The field value or NULL.

2 calls to MediaEntityHelper::getFieldPropertyValue()
MediaEntityHelper::getAssetId in src/MediaEntityHelper.php
Get the asset ID for the given media entity.
MediaEntityHelper::getExistingFileId in src/MediaEntityHelper.php
Gets the existing file ID from the given Media entity.

File

src/MediaEntityHelper.php, line 202

Class

MediaEntityHelper
Class MediaEntityHelper.

Namespace

Drupal\media_acquiadam

Code

protected function getFieldPropertyValue($fieldName) {
  if ($this->mediaEntity
    ->hasField($fieldName)) {

    /** @var \Drupal\Core\Field\FieldItemInterface $item */
    $item = $this->mediaEntity->{$fieldName}
      ->first();
    if (!empty($item)) {
      $property_name = $item
        ->mainPropertyName();
      if (isset($this->mediaEntity->{$fieldName}->{$property_name})) {
        return $this->mediaEntity->{$fieldName}->{$property_name};
      }
    }
  }
  return NULL;
}