You are here

public function Facebook::getMetadata in Media entity facebook 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/media/Source/Facebook.php \Drupal\media_entity_facebook\Plugin\media\Source\Facebook::getMetadata()

Gets the value for a metadata attribute for a given media item.

Parameters

\Drupal\media\MediaInterface $media: A media item.

string $attribute_name: Name of the attribute to fetch.

Return value

mixed|null Metadata attribute value or NULL if unavailable.

Overrides MediaSourceBase::getMetadata

File

src/Plugin/media/Source/Facebook.php, line 97

Class

Facebook
Facebook entity media source.

Namespace

Drupal\media_entity_facebook\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $attribute_name) {
  $content_url = $this
    ->getFacebookUrl($media);
  if ($content_url === FALSE) {
    return FALSE;
  }
  $data = $this->facebookFetcher
    ->getOembedData($content_url);
  if ($data === FALSE) {
    return FALSE;
  }
  switch ($attribute_name) {
    case 'author_name':
      return $data['author_name'];
    case 'width':
      return $data['width'];
    case 'height':
      return $data['height'];
    case 'url':
      return $this
        ->getFacebookUrl($media);
    case 'html':
      return $data['html'];
    default:
      return parent::getMetadata($media, $attribute_name);
  }
}