public function Image::getDefaultName in Media entity image 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/ Image.php, line 254
Class
- Image
- Provides media type plugin for Image.
Namespace
Drupal\media_entity_image\Plugin\MediaEntity\TypeCode
public function getDefaultName(MediaInterface $media) {
// The default name will be the filename of the source_field, if present,
// or the parent's defaultName implementation if it was not possible to
// retrieve the filename.
$source_field = $this->configuration['source_field'];
/** @var \Drupal\file\FileInterface $file */
if (!empty($source_field) && ($file = $media->{$source_field}->entity)) {
return $file
->getFilename();
}
return parent::getDefaultName($media);
}