2

I want to have one field for header images, but sort them by type of content. Sadly, when I try to do that, I get:

The File directory is using the following invalid tokens: [content-type:machine-name].

there is no "avaliable tokens" link under File path box, but when I click generic one, I get:

  • Current date - Tokens related to the current date and time.
  • Current page - Tokens related to the current page request.
  • Current user - Tokens related to the currently logged in user.
  • Random - Tokens related to random data.
  • Site information - Tokens for site-wide settings and other global information.
  • Variables - Tokens for variable values.

Now, I can add Node to the list with File (Field) Paths, but that's overkill. I want more basic thing - content type or more generic bundle tokens. And they are not provided. Is there something I'm missing?

  • 1
    Adding the tokens themselves is pretty easy I guess (normal hook_tokens() method based on a node object). The interesting part is altering the field validation/submission process to inject the relevant entity and base the file path on the token_replace() result. While also maintaining file naming standards and coping with errors on the fly. It's not a particularly trivial task, hence why File (Field) Paths is so full of bugs – Clive Oct 3 '13 at 9:17
  • BTW while searching try looking for "bundle" tokens in case anyone's implemented it generically for entities. The tricky part IMO is still actually performing the replacement upon file upload/save – Clive Oct 3 '13 at 9:17
  • @Clive I'm afraid that cloning File (Field) Paths might be the easiest way :| For now posting not so good, but working answer. But not going to accept it. And I'll update my question with bundles, thanks :) – Mołot Oct 3 '13 at 9:21
1

One way to do it, is to use File (Field) Paths, as node provides content type "subtokens" like:

[node:content-type:machine-name]

Problem with any other implementation will be caused by the fact that fields can be attached to things that does not have content types.

This answer is limited to nodes, so it's only a partial one, but it will do the trick in many cases.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.