You are here

protected static function GeneralEntityReferenceFormatter::getWellKnownTokenReplacements in Formatter Suite 8

Returns an array of mappings from general patterns to specific patterns.

Most entity types define tokens that map names to field values. For instance, "[node:nid]" maps to a node entity's unique numeric ID, and "[comment:title]" maps to the comment's title.

Unfortunately, there is no standardization across entity types, though there are quite a few common tokens like "created" and "changed". This makes it impossible to generically refer to "[ENTITTYPE:id]" and always get the numeric entity ID no matter what __PREFIX is.

To make generic patterns work, like those returned by the getEntityReferenceTokenPatterns() method, we need to "fix" the pattern after replacing __PREFIX and swap generic patterns for patterns for specific entity types. So "[__PREFIX:id]" converts to "[node:id]" for a node entity, and then the "fix" swaps that with "[node:nid]" so that "nid" is used for nodes. The same goes for multiple other common entity types.

Return value

string[] Returns an associative array where the keys are general patterns to replace, and the values are entity-specific patterns.

1 call to GeneralEntityReferenceFormatter::getWellKnownTokenReplacements()
GeneralEntityReferenceFormatter::viewElements in src/Plugin/Field/FieldFormatter/GeneralEntityReferenceFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/GeneralEntityReferenceFormatter.php, line 258

Class

GeneralEntityReferenceFormatter
Formats an entity reference as one or more links.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected static function getWellKnownTokenReplacements() {

  // Generic fields:
  // - id.
  // - name or title.
  // - author, owner, user, or uid.
  return [
    // Generic pattern        Entity type specific pattern.
    //
    // Core modules:
    '[aggregator_feed:id' => '[aggregator_feed:fid',
    '[aggregator_feed:name' => '[aggregator_feed:title',
    '[aggregator_feed:changed' => '[aggregator_feed:modified',
    '[aggregator_item:id' => '[aggregator_item:iid',
    '[aggregator_item:name' => '[aggregator_item:title',
    '[aggregator_item:owner' => '[aggregator_item:author',
    '[aggregator_item:user' => '[aggregator_item:author',
    '[aggregator_item:uid' => '[aggregator_item:author',
    '[aggregator_item:created' => '[aggregator_item:timestamp',
    '[comment:id' => '[commend:cid',
    '[comment:name' => '[commend:title',
    '[comment:owner' => '[commend:author',
    '[comment:user' => '[commend:author',
    '[comment:uid' => '[commend:author',
    '[content_moderation_state:author' => '[content_moderation_state:uid',
    '[content_moderation_state:owner' => '[content_moderation_state:uid',
    '[content_moderation_state:user' => '[content_moderation_state:uid',
    '[file:id]' => '[file:fid',
    '[file:title' => '[file:name',
    '[file:author' => '[file:owner',
    '[file:user' => '[file:owner',
    '[file:uid' => '[file:owner',
    '[media:id' => '[media:mid',
    '[media:title' => '[media:name',
    '[media:author' => '[media:uid',
    '[media:owner' => '[media:uid',
    '[media:user' => '[media:uid',
    '[menu_link_content:name' => '[menu_link_content:title',
    '[node:id' => '[node:nid',
    '[node:name' => '[node:title',
    '[node:owner' => '[node:author',
    '[node:user' => '[node:author',
    '[node:uid' => '[node:author',
    '[shortcut:name' => '[shortcut:title',
    '[term:id' => '[term:tid',
    '[term:title' => '[term:name',
    '[user:id' => '[user:uid',
    '[user:name' => '[user:display-name',
    '[user:title' => '[user:display-name',
    '[user:changed' => '[user:last-login',
    '[view:name' => '[view:title',
    '[vocabulary:id' => '[vocabulary:vid',
    '[vocabulary:title' => '[vocabulary:name',
    '[workspace:title' => '[workspace:name',
    '[workspace:author' => '[workspace:uid',
    '[workspace:owner' => '[workspace:uid',
    '[workspace:user' => '[workspace:uid',
    // A few contrib modules:
    '[foldershare:title' => '[foldershare:name',
    '[foldershare:author' => '[foldershare:owner',
    '[foldershare:user' => '[foldershare:owner',
    '[foldershare:uid' => '[foldershare:owner',
    '[menu-link:id' => '[menu-link:mlid',
    '[menu-link:name' => '[menu-link:title',
  ];
}