You are here

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

Class

Slideshow
Provides media type plugin for Slideshows.

Namespace

Drupal\media_entity_slideshow\Plugin\MediaEntity\Type

Code

public function getDefaultName(MediaInterface $media) {

  // The default name will be the timestamp + number of slides.
  $length = $this
    ->getField($media, 'length');
  if (!empty($length)) {
    return $this
      ->formatPlural($length, '1 slide, created on @date', '@count slides, created on @date', [
      '@date' => \Drupal::service('date.formatter')
        ->format($media
        ->getCreatedTime(), 'custom', 'd/M/Y - H:i:s'),
    ]);
  }
  return parent::getDefaultName($media);
}