diff --git a/core/modules/editor/editor.admin.inc b/core/modules/editor/editor.admin.inc index 6c03ad7c4a..5331df7233 100644 --- a/core/modules/editor/editor.admin.inc +++ b/core/modules/editor/editor.admin.inc @@ -74,7 +74,7 @@ function editor_image_upload_settings_form(Editor $editor) { '#type' => 'textfield', '#default_value' => $image_upload['directory'], '#title' => t('Upload directory'), - '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."), + '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored. This field supports tokens."), '#states' => $show_if_image_uploads_enabled, ]; diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index a1ced5747b..77b0cc0a74 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -13,6 +13,7 @@ use Drupal\Core\Ajax\CloseModalDialogCommand; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Component\Render\PlainTextOutput; /** * Provides an image dialog for text editors. @@ -100,10 +101,15 @@ public function buildForm(array $form, FormStateInterface $form_state, Editor $e $existing_file = isset($image_element['data-entity-uuid']) ? \Drupal::service('entity.repository')->loadEntityByUuid('file', $image_element['data-entity-uuid']) : NULL; $fid = $existing_file ? $existing_file->id() : NULL; + $destination = trim($image_upload['directory'], '/'); + // Replace tokens. As the tokens might contain HTML we convert it to plain + // text. + $destination = PlainTextOutput::renderFromHtml(\Drupal::token()->replace($destination)); + $form['fid'] = [ '#title' => $this->t('Image'), '#type' => 'managed_file', - '#upload_location' => $image_upload['scheme'] . '://' . $image_upload['directory'], + '#upload_location' => $image_upload['scheme'] . '://' . $destination, '#default_value' => $fid ? [$fid] : NULL, '#upload_validators' => [ 'file_validate_extensions' => ['gif png jpg jpeg'],