Problem/Motivation

Rather than declare the data types acceptable (for example 'node') and show all tokens applicable in the "Tokens available" browser, pathauto seems to name which types it will accept.

Steps to reproduce

Spend six hours trying to figure out why your perfectly-defined token type is not showing up.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mlncn created an issue. See original summary.

mlncn’s picture

Issue summary: View changes
shank115’s picture

Status: Active » Needs review

When you create a custom entity, the name of the token type in hook_token_info() must be exactly the same as the name returned by token.entity_mapper for that entity. If the names don't match, Pathauto won't recognize the tokens, and its token browser will appear empty for that entity.

Example:
Entity type ID is demo_product
Try it something like this:

function mymodule_token_entity_mapping_alter(&$mapping) {
    $mapping['demo_product'] = 'product';
  }
berdir’s picture

Status: Needs review » Postponed (maintainer needs more info)

token UI is always meant to show only the token types that are provided plus those that are global. If it's a token type for your entity type then yes, make sure it either matches the entity type or define the mapping per #3.

mlncn’s picture

Bundle-Scoped Entity Tokens provides tokens per bundle, and declares node ones to be 'node' tokens. So it does match the entity type and i would expect them to show up in Pathauto.

I'll admit that pathauto really doesn't need these tokens, because patterns are defined per-bundle anyway. (It was just i was looking in Pathauto to see if my module was working lol.)

(What would be useful and cool, but i know cannot happen without some very custom not-in-Drupal-core way to alter Pathauto's behavior, is that if Bundle-Scoped Entity Tokens are available then only show the bundle-scoped entity tokens for the current pattern, so you only see the applicable fields when defining your pattern and not Article fields for a Page pattern etc.)