public static function MediaHelper::prepareFileDestination in Lightning Media 8.4
Same name and namespace in other branches
- 8 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::prepareFileDestination()
- 8.2 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::prepareFileDestination()
- 8.3 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.
2 calls to MediaHelper::prepareFileDestination()
- MediaHelper::useFile in src/
MediaHelper.php - Attaches a file entity to a media entity.
- MediaHelperTest::testPrepareFileDestination in tests/
src/ Kernel/ MediaHelperTest.php - @covers ::prepareFileDestination @covers ::getSourceField
File
- src/
MediaHelper.php, line 215
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();
$options = FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS;
\Drupal::service('file_system')
->prepareDirectory($destination, $options);
return $destination;
}