Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gutenberg
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
gutenberg
Commits
d8c3edb4
Commit
d8c3edb4
authored
7 months ago
by
J P
Committed by
Marco Fernandes
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
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
!143
Issue #3449709 Use medias file settings and replace tokens in upload path
Pipeline
#184375
passed with warnings
7 months ago
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gutenberg.services.yml
+1
-1
1 addition, 1 deletion
gutenberg.services.yml
src/MediaUploader.php
+16
-4
16 additions, 4 deletions
src/MediaUploader.php
with
17 additions
and
5 deletions
gutenberg.services.yml
+
1
−
1
View file @
d8c3edb4
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
src/MediaUploader.php
+
16
−
4
View file @
d8c3edb4
...
...
@@ -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
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment