public static function MediaHelper::prepareFileDestination in Lightning Media 8.3
Same name and namespace in other branches
- 8.4 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::prepareFileDestination()
- 8 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::prepareFileDestination()
- 8.2 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::prepareFileDestination()
Prepares the destination directory for a file attached to a media entity.
Parameters
\Drupal\media\MediaInterface $entity: The media entity.
Return value
string The destination directory URI.
1 call to MediaHelper::prepareFileDestination()
- MediaHelper::useFile in src/
MediaHelper.php - Attaches a file entity to a media entity.
File
- src/
MediaHelper.php, line 219
Class
- MediaHelper
- Provides helper methods for dealing with media entities.
Namespace
Drupal\lightning_mediaCode
public static function prepareFileDestination(MediaInterface $entity) {
/** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */
$item = static::getSourceField($entity)
->first();
$destination = $item
->getUploadLocation();
// Support both Drupal 8.7's API and its antecedents. We need to call the
// deprecated symbols in an obscure way to prevent failures during
// deprecation testing.
if (version_compare(\Drupal::VERSION, '8.7.0', '>=')) {
$options = FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS;
\Drupal::service('file_system')
->prepareDirectory($destination, $options);
}
else {
$options = constant('FILE_CREATE_DIRECTORY') | constant('FILE_MODIFY_PERMISSIONS');
$function = 'file_prepare_directory';
$function($destination, $options);
}
return $destination;
}