Problem/Motivation

Allow Drupal date tokens to be used in the "Upload Directory" path, much like they are used for the upload path in Image fields of Content Types.

That way instead of inline-images one could have inline-images/[date:custom:Y]/[date:custom:m]

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-2830210

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Chayemor created an issue. See original summary.

wim leers’s picture

Title: Allow Drupal date tokens to be used in upload directory path in CKEditor » Allow tokens to be used in Text Editor image upload directory path
Component: ckeditor.module » editor.module
Issue tags: -ckeditor

The image upload functionality was introduced in #1932652: Add image uploading to WYSIWYGs through editor.module. We specifically didn't support tokens in the upload path to get to an MVP faster. The fact that this is the first explicit issue requesting this, shows that it's rarely necessary.

If you (or somebody else) wants to work on supporting this, including test coverage, then we'd totally welcome that. I'll provide reviews.

But it's probably better to instead do this as a contributed module. Something like editor_advanced_image, in analogy with https://www.drupal.org/project/editor_advanced_link.

Chayemor’s picture

I'm working on providing the simple module I did to allow for general token use (like date or site name). I think it best to have it as a contributed module, see if it even gets used at all.

Thanks.

wim leers’s picture

Cool! :)

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

finalred’s picture

a token-path would be great

hkirsman’s picture

+1

Client asked for this kind of image hieararchy:

images
	content_type_1
			field_1
			field_2
			inline
	content_type_2
			field_1
			field_2
			inline

But I also see the date token very logical because the image field is already using it. Why shouldn't there be then the same functionality for inline images.

madsciencepro’s picture

+1

Going on my 3rd year in the Drupal world and I'm always fascinated that this CMS doesn't really manage large amounts of content well. One folder is fine for small sites, but isn't the Drupal audience medium to large sites? I'm kinda shocked that more people haven't piped up about expanding the use of tokens on sites for situations like this.

I'm working on a D8 university site where departments upload a lot of documents. I've been using Paragraphs for a 'Downloads' section to keep it clean, but now I'm getting a lot of requests for inline links to document files. IMCE isn't the answer because that's what made our old D7 site a gigantic mess. I have an army of non-technical Editors that drew the short straw in their department, so I'm aiming for simple and fast. Adding date tokens would at least prevent an 'inline-files' folder full of thousands of files.

I don't have the resources for a DAM or the know-how to even connect it to Drupal if I did. My dream situation is a Media Browser that checks the page Taxonomy and only shows the editor the files/folders that belong to that department. Like biology/images, biology/files, biology/podcasts, etc.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tepelena’s picture

This would be a great feature. Currently, I am using AWS S3 and am running into problems if we try to embed an image with the same filename. If tokens were allowed it would solve this problem and it would also make it easy to track files on S3 by user.

kiwi_steve’s picture

+1, I absolutely want this - clumping everything into one directory is a terrible idea and 'performance' is a (mostly) terrible excuse for doing it (IMHO, YMMV). If Drupal 9 (or 10, or 11, or whatever) comes along and changes everything the way D8 did and I suddenly want all my data out in an easy way then I don't want to have to fight to find it and/or get it.

I'm producing large quantities of information on thousands of bits of equipment from hundreds of manufacturers and distributors and I absolutely want all images, attached as an image field or inline, to be in the same subfolder - one specific to that piece of equipment... I've created a hierarchical folder structure for attached images, I just can't use it for the inline ones (nor can I easily Colorbox them without, perhaps, stepping outside the security advisory umbrella - but thats another issue).

I'm happy to try and help with this if its going to be a difficult job - testing, documentation, possibly coding... let me know.

Cheers

Steve

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

johnnny83’s picture

+1 An absolutely necessary feature

ipumpkin’s picture

Status: Active » Needs review
StatusFileSize
new1.48 KB
mahtab_alam’s picture

StatusFileSize
new1.37 KB

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

brunodbo’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Patches in #14/#15 seem to do the trick: tokens configured in the 'Upload directory' for the WYSIWYG image field are replaced in the image destination. Still needed AFAICT:

- Let's add 'This field supports tokens.' to the 'Upload directory' field description.
- Tests

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

g089h515r806’s picture

I have created a contrib module base on the patch:
https://www.drupal.org/project/inline_image_token

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

HYX900’s picture

Hi all, any updates on this making it to core eventually?

I work with some Drupal sites that handle hundreds of image uploads a day. It's a complete mess to have all the images go in one folder. In one month we'd have thousands, and in a year we'd have tens of thousands of images in that folder. It would be great to no longer have to rely on a custom module that may or may not continue working in the future.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kwfinken’s picture

This is still needed!

andregp’s picture

StatusFileSize
new2.21 KB
new2.1 KB

Just a simple reroll for 9.5. I also updated the description of 'Upload directory' (according to #17).
Still needs work for adding tests.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Title: Allow tokens to be used in Text Editor image upload directory path » Allow tokens to be used in Text Editor/CKEditor 5 image upload directory path
Status: Needs work » Needs review
Issue tags: +Needs framework manager review
Related issues: +#3351476: CKEditor 5 doesnt support directory tokens for inline images, +#3231341: Deprecate EditorLinkDialog, EditorImageDialog and EditorMediaDialog in Drupal 10.1 for removal in Drupal 11, +#1833716: WYSIWYG: Introduce "Text editors" as part of filter format configuration

Closed #3351476: CKEditor 5 doesnt support directory tokens for inline images as a duplicate of this.

This patch is correctly updating editor_image_upload_settings_form() and EditorImageDialog. But EditorImageDialog is going away: #3231341: Deprecate EditorLinkDialog, EditorImageDialog and EditorMediaDialog in Drupal 10.1 for removal in Drupal 11. Still, CKEditor 5's \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image::buildConfigurationForm() continues to call editor_image_upload_settings_form().

Which brings up an interesting question … perhaps this should actually be converted into a CKEditor 5 issue? due to #3231341, the bulk of the changes would actually have to happen in the CKEditor 5 module, not the Text Editor module?

Also related: #3231354: [PP-2] [META] Discuss: merge the Editor config entity into the FilterFormat config entity, at which point it quite possibly makes sense to drop \Drupal\editor\EditorInterface::getImageUploadSettings() altogether? The very reason that configuration was stored on the general Text Editor config entity was to maximize the ability to switch between different text editors back in #1833716: WYSIWYG: Introduce "Text editors" as part of filter format configuration, over 10 years ago 😳, by putting configuration that could be shared between text editors in the general Text Editor config entity rather than the text-editor-plugin-specific settings.

But in that decade, no notable alternative text editor has sprung up in the contributed module space. So why keep this API surface complexity? Why not drop it exactly at the time when we are modifying EditorInterface anyway (i.e. merging it with FilterFormatInterface).

Tagging Needs framework manager review for that.

g089h515r806’s picture

For Ckeditor5 in drupal 10, 1 line code change could fixed it:

change

$destination = $image_upload['scheme'] . '://' . $image_upload['directory'];

to

$destination = $image_upload['scheme'] . '://' . \Drupal::token()->replace($image_upload['directory']);

in "upload" function of file "core\modules\ckeditor5\src\Controller\CKEditor5ImageController.php"

Akshay kashyap made their first commit to this issue’s fork.

alexpott’s picture

@Wim Leers so should we block this on #3231354: [PP-2] [META] Discuss: merge the Editor config entity into the FilterFormat config entity? My gut feel is that we should do the smallest change possible here and only change ckeditor5. And if #3231354: [PP-2] [META] Discuss: merge the Editor config entity into the FilterFormat config entity goes ahead it'll take care of the other stuff in #30.

FWIW we can use \Drupal::token()->replacePlain() here.

smustgrave’s picture

Status: Needs review » Postponed

#34 makes it sound like this should be postponed. Or moved to ckeditor5.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alezu’s picture

StatusFileSize
new1.26 KB

Let me put this temporary patch for CKEditor5 here.
Just for note - at least the old ckeditor seems to be loaded without any context, so it's hardly possible to use any tokens except global ones there.

anche’s picture

all these patches work only with the date? I'm trying [node:nid] and it doesn't work (#38) :(

alezu’s picture

Hi Anche, there is an example of workaround for a similar case. https://drupal-coder.ru/blog/privatnye-kartinki-ckeditor-drupal-dinamich...
The post is in Russian but everything is clear from the code.

anche’s picture

Alezu, thanx a lot! It helped me.

loze’s picture

here's a reroll of the temporary fix in #38 that should work with 10.3.0

kopeboy’s picture

Status: Postponed » Reviewed & tested by the community

Patch #42 worked with Drupal 10.3.6 too!
(not sure if this issue can be marked for 10.3.x or 10.4.x though)

I tested inline-files/[date:custom:Y]-[date:custom:m] as suggested in issue body.

Maybe we want separate follow up issues for:

  1. improving the UX, for example by adding a link to Browse available tokens
  2. making any other contrib module use tokens out of the box (not sure it's possible or they are expected to put some code anyway to enable token replacement in the fields they define)
  3. making other tokens (non-globally available ones) work, for example related to the parent entity having the CKE text field (for example [node:nid] doesn't work, as expected?).

..so that we can include this quick fix soon?

Regarding 2 for example, the editor_file contrib module (that works like core editor's inline images but for files, creating links) wasn't substituting tokens out-of-the-box with this patch, but it started working fine with this patch.

mxr576’s picture

Status: Reviewed & tested by the community » Needs work

Moving back to needs work since the "needs test" tag is on the issue and I haven't seen any test coverage in MR#3891 so far.

sirclickalot’s picture

Patch #42 works in Drupal 10.3.10.

Personally, I think this is is quite a crucial feature to have because without it, sites' sites/default/files/inline-images folders will be in danger of becoming dangerously bloated, I know mine is!

boobaa’s picture

Version: 11.x-dev » 11.1.x-dev
Component: editor.module » ckeditor5.module
StatusFileSize
new2.09 KB

Attaching a proper DI reroll of MR#3897 that's compatible with 11.1.7.

quietone’s picture

Version: 11.1.x-dev » 11.x-dev
Issue summary: View changes

In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Also mentioned on the version section of the list of issue fields documentation.

immaculatexavier made their first commit to this issue’s fork.

mrinalini9 changed the visibility of the branch 11.x to hidden.

mrinalini9 changed the visibility of the branch 11.x to active.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

andreic’s picture

Patch for Drupal 10.6.