public static function prepareFileDestination(MediaInterface $entity) {
    /** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */
    $item = static::getSourceField($entity)->first();

    $dir = $item->getUploadLocation();
    $is_ready = file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

    if ($is_ready) {
      return $dir;
    }
    else {
      throw new \RuntimeException('Could not prepare ' . $dir . ' for writing');
    }
  }
public static function prepareFileDestination(MediaInterface $entity) {
    /** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */
    $item = static::getSourceField($entity)->first();

    $dir = $item->getUploadLocation();
    $is_ready = file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

    if ($is_ready) {
      return $dir;
    }
    else {
      throw new \RuntimeException('Could not prepare ' . $dir . ' for writing');
    }
  }
public static function prepareFileDestination ( MediaInterface $ entity ) { /** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */ $ item = static :: getSourceField ( $ entity ) -> first ( ) ; $ dir = $ item -> getUploadLocation ( ) ; $ is_ready = file_prepare_directory ( $ dir , FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS ) ; if ( $ is_ready ) { return $ dir ; } else { throw new \ RuntimeException ( 'Could not prepare ' . $ dir . ' for writing' ) ; } }
Prepares the destination directory for a file attached to a media entity.

@param \Drupal\media\MediaInterface $entity
The media entity.

@return string
The destination directory URI.

@throws \RuntimeException
If the destination directory is not writable.
Prepares the destination directory for a file attached to a media entity .