We use the following pattern for a node pathauto url alias which were working last year as I can see from the url aliases of the older nodes. I think it stopped working with the current version 8.x-1.9:

[node:field_legislature:entity:parliament:entity:url_basis]/[node:field_legislature:entity:identifier]/abstimmungen/[node:title]

Let me explain the problem with the first token:
field_legislature is a Field API field of a node referencing to a custom entity of type parliament_period. This entity has a reference field "parliament" to another entity of the same-name type "parliament" from where we want to use the "url_alias" field.

The old alias are correct like
/bayern/18/abstimmungen/einheitliches-oeffnungskonzept-fuer-den-einzelhandel
but the new aliases only consist of the third and fourth alias part:
/abstimmungen/einheitliches-oeffnungskonzept-fuer-den-einzelhandel

The first tokens [node:field_legislature:entity:parliament:entity:url_basis] and [node:field_legislature:entity:identifier] are not converted anymore.

I dived deeper into the code and found the following place:

field_tokens()

// Ensure the entity has the requested field and that the token for it is
// defined by token.module.
if (!$entity->hasField($field_name) || _token_module($data['token_type'], $token_name) != 'token') {
   continue;
}

Although I defined the tokens for the parliament field (in parliament_period entity) and the url_alias field (in parliament entity) this place always stops field_tokens() before it can reach the interesting part of the method regarding chaining the tokens. And here is the issue:

_token_module($data['token_type'], $token_name) != 'token'

can only be true if I define the token in hook_token_info() the following way:

  $type_parliament_period = [
    'name' => t('Parliament period'),
    'description' => t('Tokens related to parliament periods.'),
    'needs-data' => 'parliament_period',
  ];

  $parliament_period['parliament'] = [
    'name' => t('Parliament'),
    'module' => 'token'
  ];

  return [
    'types' => [
      'parliament_period' => $type_parliament_period
    ],
    'tokens' => [
      'parliament_period' => $parliament_period
    ],
  ];

As I found no documentation about this 'module' array key for hook_token_info() I wonder if this really is the way to achive this chaining. or if this check was added to field_tokens() by accident?!

Comments

tobiberlin created an issue.