MediaName.php in Migrate File Entities to Media Entities 8
File
src/Plugin/migrate/process/MediaName.phpView source
<?php
namespace Drupal\migrate_file_to_media\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
*
* @MigrateProcessPlugin(
* id = "media_name"
* )
*/
class MediaName extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($source, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Use alt tag if available.
if (!empty($row
->getSourceProperty('alt'))) {
return substr($row
->getSourceProperty('alt'), 0, 255);
}
elseif (!empty($source)) {
return $source;
}
return '';
}
}