Skip to content
Snippets Groups Projects
Commit d8c3edb4 authored by J P's avatar J P Committed by Marco Fernandes
Browse files

Issue #3449709 Use medias file settings and replace tokens in upload path

parent ea236c7f
No related branches found
No related tags found
1 merge request!143Issue #3449709 Use medias file settings and replace tokens in upload path
Pipeline #184375 passed with warnings
......@@ -79,7 +79,7 @@ services:
arguments: ['@entity_type.manager', '@current_user']
gutenberg.media_uploader:
class: Drupal\gutenberg\MediaUploader
arguments: ['@file_system']
arguments: ['@file_system', '@token']
gutenberg.entity_type.data_provider_manager:
class: Drupal\gutenberg\DataProvider\EntityDataProviderManager
tags:
......
......@@ -5,6 +5,7 @@ namespace Drupal\gutenberg;
use Drupal\Component\Utility\Bytes;
use Drupal\Component\Utility\Environment;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Utility\Token;
use Drupal\editor\Entity\Editor;
use Symfony\Component\HttpFoundation\File\UploadedFile;
......@@ -22,14 +23,22 @@ class MediaUploader implements MediaUploaderInterface {
*/
protected $fileSystem;
/**
* Drupal token service container.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* MediaUploader constructor.
*
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
*/
public function __construct(FileSystemInterface $file_system) {
public function __construct(FileSystemInterface $file_system, Token $token) {
$this->fileSystem = $file_system;
$this->token = $token;
}
/**
......@@ -37,9 +46,12 @@ class MediaUploader implements MediaUploaderInterface {
*/
public function upload(string $form_field_name, UploadedFile $uploaded_file, Editor $editor, array $file_settings = []) {
$image_settings = $editor->getImageUploadSettings();
// @todo use the relevant media file settings over the Editor's "Image" plugin one?
// Or ultimately just use Drupal's builtin file_managed in a modal to
// handle all of this logic like CKeditor does.
$image_settings['directory'] = $this->token->replace($file_settings['file_directory'] ?: $image_settings['directory']);
$image_settings['scheme'] = $file_settings['uri_scheme'] ?: $image_settings['scheme'];
$image_settings['max_size'] = $file_settings['max_filesize'] ?: $image_settings['max_size'];
$image_settings['max_dimensions'] = $file_settings['max_resolution'] ?: $image_settings['max_dimensions'];
$destination = $image_settings['scheme'] . '://' . $image_settings['directory'];
if (!$this->fileSystem->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment