Hello,

Please, help with drafting filefield_paths rules when uploaded files will be stored in a folders depending on the term selected from the vocabulary Category

It's possible in 8.x?

[node:field_category] returns string with superfluous content (language code, html tags etc)
files/<a href="/en/taxonomy/term/21" hreflang="en">category_term</a>/file.doc

Thanks

Comments

cka3o4h1k created an issue. See original summary.

cka3o4h1k’s picture

Issue summary: View changes
cka3o4h1k’s picture

Issue summary: View changes
cka3o4h1k’s picture

Issue summary: View changes
cka3o4h1k’s picture

Issue summary: View changes
cka3o4h1k’s picture

Issue summary: View changes
Deciphered’s picture

Status: Active » Fixed

This is expected behaviour with the token you are using. The token is provided by the Token module, and Token module Field tokens are run through the Token view mode for the particular bundle.

In Drupal 7 I would always recommend using the the Entity API modules Entity Tokens sub module, but that is not currently available for Drupal 8.

As far as I know, the current approach to achieve what you want is to do the following:

  1. Go to the 'Manage Display' settings for your Content type.
  2. Click the checkbox for 'Token' under the 'Custom display settings' section and hit 'Save'.
  3. Click on the 'Token' view mode tab.
  4. Change the formatter settings for your field so that it doesn't 'Link to the referenced entity'.

You can test what a token will render as by creating a node, then running the following code via the Devel PHP interface:

$node = \Drupal\node\Entity\Node::load(NODE_ID); // replace NODE_ID with your Node's ID.
$text = "[TOKEN]"; // Replace TOKEN with the desired token to test.

dpm(\Drupal::service('token')->replace($text, ['node' => $node]));

I will be beginning the port of my Field Tokens module today, which provides similar functionality to the Entity Tokens sub-module, allowing you to achieve the same goal as above without messing with the Formatter settings.

Deciphered’s picture

Beta 1 of Field Tokens released, you could use the following token now to achieve what you need: [node:field_category-property:0:entity:name]

Status: Fixed » Closed (fixed)

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

cesarg’s picture

#8 worked for me, thank you very much! @Deciphered