You are here

public function Instagram::getDefaultName in Media entity Instagram 8

Provide a default name for the media.

Plugins defining media bundles are suggested to override this method and provide a default name, to be used when there is no user-defined label available.

Parameters

\Drupal\media_entity\MediaInterface $media: The media object.

Return value

string The string that should be used as default media name.

Overrides MediaTypeBase::getDefaultName

File

src/Plugin/MediaEntity/Type/Instagram.php, line 285

Class

Instagram
Provides media type plugin for Instagram.

Namespace

Drupal\media_entity_instagram\Plugin\MediaEntity\Type

Code

public function getDefaultName(MediaInterface $media) {

  // Try to get some fields that need the API, if not available, just use the
  // shortcode as default name.
  $username = $this
    ->getField($media, 'username');
  $id = $this
    ->getField($media, 'id');
  if ($username && $id) {
    return $username . ' - ' . $id;
  }
  else {
    $code = $this
      ->getField($media, 'shortcode');
    if (!empty($code)) {
      return $code;
    }
  }
  return parent::getDefaultName($media);
}