Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you have the Token module enabled in Drupal 7 and you save a File field definition without changing any of the defaults, the Token validation will fail with the following message:
The File directory is using the following invalid tokens: [date:custom:Y], [date:custom:m].
Steps
- Launch Simplytest.me with Token for Drupal 8: http://ply.st/token
- Install site
- Enable the Token module: /admin/modules
- Goto the Article Image field settings page and hit the Save settings button: /admin/structure/types/manage/article/fields/node.article.field_image
Comment | File | Size | Author |
---|---|---|---|
#17 | file_field_date_token-2642160-17.patch | 2.66 KB | hussainweb |
|
Comments
Comment #2
Deciphered CreditAttribution: Deciphered commentedBumping this issue to Major, as not being able to edit a file field settings form without changing the default file directory is a pretty big issue.
Comment #3
Deciphered CreditAttribution: Deciphered as a volunteer commentedSimple issue, simple fix, patch attached.
It's worth noting that while the Date token type is not a global token as it's definition defines that it needs data, it doesn't actually need data.
Comment #4
hussainwebI think there is a reason it needs data. See #943028: 'Date' token namespace is ambiguous.
In this case, you can use [current-date:custom:Y] and so on...
Comment #5
Deciphered CreditAttribution: Deciphered as a volunteer commented@hussainweb, the problem is that core doesn't use [current-date:...], it uses [date:...], so if you enable the Token module it is implying that core is broken. I'm not stating that it isn't, just that the Token module currently prevents usage of core defaults.
Like I said above though, while the Date token type implies is needs data, it doesn't, as it provides a default value, the current date, if no data is provided. The attached patch resolves the issue and continues to pass the tests. If anything else can be done to expedite this issue I would be happy to do so, as this issue breaks File (Field) Paths tests when the Token module is enabled.
Comment #6
BerdirThis works as a workaround for me, committed to unblock your tests. Agreed we can't block the form because of that, and it's a core inconsistency that we can't fully solve here.
Keeping open to extend with test coverage, we already have tests for this UI, should be easy to verify that we can submit the form.
Comment #8
Deciphered CreditAttribution: Deciphered as a volunteer commentedThanks @Berdir, I appreciate that.
Will be more than happy to supply a patch to add there appropriate tests, hopefully within three next few hours.
Comment #9
BerdirOk. While doing that, please also add a comment with reference to the core issue, I forgot to do that.
Comment #10
Deciphered CreditAttribution: Deciphered as a volunteer commentedComment #11
BerdirThanks. Lets keep this in the same test method, otherwise it doubles test execution time.
Also, I'd like to see a positive confirmation message, not the negative one. That would not ail in case the error message is slightly different.
Comment #12
Deciphered CreditAttribution: Deciphered as a volunteer commentedDone and done.
Comment #13
hussainwebI am wondering if we should extend this to other input boxes (even on the same page). I am trying to write tests for another issue and of course, the date tokens can't work there.
Comment #14
hussainwebJust FYI, I found a related issue in core here. I filed #2642674: Tokens not replaced in file/widget field descriptions.
Comment #15
hussainwebSince we might need to test other fields later, let's not remove them. The tests I am planning to add won't work with image field until the core issue is fixed and I am not sure how long that will take.
Comment #16
BerdirNeeds a reroll now.
Was going to say that I'm not sure about keeping the fields if we're not using them, but we are now using them for a different test.
Comment #17
hussainwebRerolled...
Comment #18
BerdirThanks, committed.
Comment #21
DCLoganGuy CreditAttribution: DCLoganGuy commentedSorry, I get it. Our issue is we are using filefield_paths.
Please disregard.
Is there a reason this issue was not fixed for drupal 7.x? We are having the same issue.
Drupal 7.92
Token 7.x-1.9
When creating a file field type for a content type, the File Directory defaults to [date:custom:Y]-[date:custom:m] which is invalid.
thanks