public function Pinterest::getDefaultName in Media entity Pinterest 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/ Pinterest.php, line 261
Class
- Provides media type plugin for Pinterest.
Namespace
Drupal\media_entity_pinterest\Plugin\MediaEntity\TypeCode
public function getDefaultName(MediaInterface $media) {
$id = $this
->getField($media, 'id');
$board = $this
->getField($media, 'board');
$user = $this
->getField($media, 'user');
// The default name will be the Pin ID for Pins.
if (!empty($id)) {
return $id;
}
// The default name will be the username and board slug for Boards.
if (!empty($user) && !empty($board)) {
return $user . ' - ' . $board;
}
// The default name will be the username for Profiles.
if (!empty($user) && empty($board)) {
return $user;
}
return parent::getDefaultName($media);
}