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

  1. Launch Simplytest.me with Token for Drupal 8: http://ply.st/token
  2. Install site
  3. Enable the Token module: /admin/modules
  4. Goto the Article Image field settings page and hit the Save settings button: /admin/structure/types/manage/article/fields/node.article.field_image
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Deciphered created an issue. See original summary.

Deciphered’s picture

Priority: Normal » Major

Bumping 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.

Deciphered’s picture

Status: Active » Needs review
FileSize
759 bytes

Simple 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.

hussainweb’s picture

I 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...

Deciphered’s picture

@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.

Berdir’s picture

Title: Default file field tokens ([date:custom:Y]-[date:custom:m]) fail Token validation. » Needs tests: Default file field tokens ([date:custom:Y]-[date:custom:m]) fail Token validation.
Status: Needs review » Needs work
Issue tags: +Needs tests

This 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.

  • Berdir committed 95c5bd9 on 8.x-1.x authored by Deciphered
    Issue #2642160 by Deciphered: Default file field tokens ([date:custom:Y...
Deciphered’s picture

Thanks @Berdir, I appreciate that.

Will be more than happy to supply a patch to add there appropriate tests, hopefully within three next few hours.

Berdir’s picture

Ok. While doing that, please also add a comment with reference to the core issue, I forgot to do that.

Deciphered’s picture

Status: Needs work » Needs review
FileSize
2.63 KB
Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Tests/TokenFieldUiTest.php
@@ -39,21 +39,29 @@ class TokenFieldUiTest extends TokenTestBase {
     $this->assertLinkByHref('token/tree');
   }
+
+  public function testFileDefaults() {
+    $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image', [], t('Save settings'));

Thanks. 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.

Deciphered’s picture

Status: Needs work » Needs review
FileSize
1.2 KB
2.52 KB

Done and done.

hussainweb’s picture

I 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.

hussainweb’s picture

Just FYI, I found a related issue in core here. I filed #2642674: Tokens not replaced in file/widget field descriptions.

hussainweb’s picture

Since 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.

Berdir’s picture

Status: Needs review » Needs work

Needs 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.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
2.66 KB

Rerolled...

Berdir’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Thanks, committed.

  • Berdir committed 9bc1322 on 8.x-1.x authored by hussainweb
    Issue #2642160 by Deciphered, hussainweb: Tests for: Default file field...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

DCLoganGuy’s picture

Issue summary: View changes

Sorry, 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