Patch 3430059 editor_file
The snippet can be accessed without any authentication.
Authored by
Pierre
editor_file-3430059-8.diff 4.72 KiB
diff --git a/composer.json b/composer.json
index b4fc67a8177dcf6765a5f02fa2b04fecf9d09fa1..cf353ef195600466440e7a61479a9ae9c5c2a353 100644
--- a/composer.json
+++ b/composer.json
@@ -7,8 +7,5 @@
"support": {
"issues": "https://www.drupal.org/project/issues/editor_file",
"source": "https://git.drupalcode.org/project/editor_file"
- },
- "require": {
- "drupal/core": "^9.4 || ^10"
}
}
diff --git a/editor_file.admin.inc b/editor_file.admin.inc
index 225f6c422e7c0fcad94c3a9db1aa8a5aecc80a54..b54facefeac013d784dfba0cc35e41c679607626 100644
--- a/editor_file.admin.inc
+++ b/editor_file.admin.inc
@@ -95,7 +95,7 @@ function editor_file_upload_settings_form(Editor $editor) {
'#states' => $show_if_file_uploads_enabled,
];
- $default_max_size = format_size(Environment::getUploadMaxSize());
+ $default_max_size = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.2.0', fn() => \Drupal\Core\StringTranslation\ByteSizeMarkup::create(Environment::getUploadMaxSize()), fn() => format_size(Environment::getUploadMaxSize()));
$form['max_size'] = [
'#type' => 'textfield',
'#default_value' => $file_upload['max_size'],
diff --git a/editor_file.info.yml b/editor_file.info.yml
index 5468c3139964408e414b8879dc3d245358fc03e8..f776196ebac1ba2f6fc35d26c3a362cede86cf20 100644
--- a/editor_file.info.yml
+++ b/editor_file.info.yml
@@ -1,7 +1,7 @@
name: 'Editor File Upload'
type: module
description: 'Allow users to link uploaded files in the text Editor.'
-core_version_requirement: ^9.4 || ^10
+core_version_requirement: ^10.3 || ^11
dependencies:
- drupal:editor
- drupal:filter
diff --git a/src/Form/EditorFileDialog.php b/src/Form/EditorFileDialog.php
index ead870e7d9fb514a056d31bb7f34772af08177d8..b32a7ea2e8098f1c83f026d0c1434180f4327d9b 100644
--- a/src/Form/EditorFileDialog.php
+++ b/src/Form/EditorFileDialog.php
@@ -219,7 +219,8 @@ class EditorFileDialog extends FormBase implements BaseFormIdInterface {
$settings = $form_state->get('file_upload_settings');
// Validate the uploaded file extension.
- $error = file_validate_extensions($file, $settings['extensions'] ?? 'txt');
+ $extensions = $settings['extensions'] ?? 'txt';
+ $error = \Drupal::service('file.validator')->validate($file, ['FileExtension' => ['extensions' => $extensions]]);
if (!empty($error)) {
$form_state->setErrorByName('fid', reset($error));
return;
@@ -227,7 +228,7 @@ class EditorFileDialog extends FormBase implements BaseFormIdInterface {
// Validate the file size.
$max_filesize = !empty($settings['max_size']) ? min(Bytes::toNumber($settings['max_size']), Environment::getUploadMaxSize()) : Environment::getUploadMaxSize();
- $error = file_validate_size($file, $max_filesize);
+ $error = \Drupal::service('file.validator')->validate($file, ['FileSizeLimit' => ['fileLimit' => $max_filesize]]);
if (!empty($error)) {
$form_state->setErrorByName('fid', reset($error));
}
@@ -268,7 +269,7 @@ class EditorFileDialog extends FormBase implements BaseFormIdInterface {
// Add a specific class for each and every mime type.
'file--mime-' . strtr($mime_type, ['/' => '-', '.' => '-']),
// Add a more general class for groups of well known MIME types.
- 'file--' . file_icon_class($mime_type),
+ 'file--' . \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.3.0', fn() => \Drupal\file\IconMimeTypes::getIconClass($mime_type), fn() => file_icon_class($mime_type)),
];
// Merge with existing classes (eg: those added w/ Editor Advanced Link).
if (!empty($form_state->getValue('attributes')['class'])) {
diff --git a/src/Plugin/CKEditor5Plugin/File.php b/src/Plugin/CKEditor5Plugin/File.php
index 8e7c7a0773b9b3a10e274951bf9529647a3a4ac0..742f74a4f00e60086718a33613ef368136ae9b8e 100644
--- a/src/Plugin/CKEditor5Plugin/File.php
+++ b/src/Plugin/CKEditor5Plugin/File.php
@@ -15,6 +15,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
+use Drupal\Core\StringTranslation\ByteSizeMarkup;
use Drupal\editor\EditorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -183,7 +184,7 @@ class File extends CKEditor5PluginDefault implements CKEditor5PluginConfigurable
'#states' => $show_if_file_uploads_enabled,
];
- $default_max_size = format_size(Environment::getUploadMaxSize());
+ $default_max_size = ByteSizeMarkup::create(Environment::getUploadMaxSize());
$form['max_size'] = [
'#type' => 'textfield',
'#default_value' => $this->configuration['max_size'],
Please register or sign in to comment