You are here

public function Twitter::getDefaultName in Media entity Twitter 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/Twitter.php, line 476

Class

Twitter
Provides media type plugin for Twitter.

Namespace

Drupal\media_entity_twitter\Plugin\MediaEntity\Type

Code

public function getDefaultName(MediaInterface $media) {

  // The default name will be the twitter username of the author + the
  // tweet ID.
  $user = $this
    ->getField($media, 'user');
  $id = $this
    ->getField($media, 'id');
  if (!empty($user) && !empty($id)) {
    return $user . ' - ' . $id;
  }
  return parent::getDefaultName($media);
}