You are here

public function Facebook::getField in Media entity facebook 8

Gets a media-related field/value.

Parameters

MediaInterface $media: Media object.

string $name: Name of field to fetch.

Return value

mixed Field value or FALSE if data unavailable.

Overrides MediaTypeInterface::getField

File

src/Plugin/MediaEntity/Type/Facebook.php, line 197

Class

Facebook
Provides media type plugin for Facebook.

Namespace

Drupal\media_entity_facebook\Plugin\MediaEntity\Type

Code

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