You are here

protected static function GeneralEntityReferenceFormatter::getWellKnownTokenPrefixExceptions in Formatter Suite 8

Returns an array of special mappings from entity types to token prefixes.

By strong convention, the token prefix (e.g. "node") is the entity type. However, this is not required. Unfortunately, Drupal core's token API does not provide a way to look up the prefix for an entity type.

This is a problem since we need to map the entity type to the prefix so that the token list added to the formatter UI is appropriate to the entity type being formatted.

The table returned here is a mapping from known core entity types to their prefixes *IF* the prefix does not match the entity type.

Return value

string[] Returns an associative array where keys are entity types and values are the corresponding token prefix. Only exceptions are included where the prefix does not match the entity type.

2 calls to GeneralEntityReferenceFormatter::getWellKnownTokenPrefixExceptions()
GeneralEntityReferenceFormatter::settingsForm in src/Plugin/Field/FieldFormatter/GeneralEntityReferenceFormatter.php
Returns a form to configure settings for the formatter.
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 343

Class

GeneralEntityReferenceFormatter
Formats an entity reference as one or more links.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected static function getWellKnownTokenPrefixExceptions() {

  // The following content entity types are defined in Drupal core:
  //
  // Content entity type       Token prefix              Defined.
  // -------------------       ------------              -------.
  // aggregator_feed           aggregator_feed           automatic.
  // aggregator_item           aggregator_item           automatic.
  // block_content             block_content             automatic.
  // comment                   comment                   custom.
  // contact_message           contact_message           automatic.
  // content_moderation_state  content_moderation_state  automatic.
  // file                      file                      custom.
  // media                     media                     automatic.
  // menu_link_content         menu_link_content         automatic.
  // node                      node                      custom.
  // path_alias                path_alias                automatic.
  // shortcut                  shortcut                  automatic.
  // taxonomy_term             term                      custom.
  // user                      user                      custom.
  // workspace                 workspace                 automatic.
  //
  // The following configuration entity types are defined in Drupal core:
  //
  // Config entity type        Token prefix              Defined.
  // ------------------        ------------              -------.
  // block                     --NO TOKENS--.
  // block_cntent_type         --NO TOKENS--.
  // comment_type              --NO TOKENS--.
  // configurable_language     --NO TOKENS--.
  // contact_form              --NO TOKENS--.
  // editor                    --NO TOKENS--.
  // field_config              --NO TOKENS--.
  // field_storage_config      --NO TOKENS--.
  // filter_format             --NO TOKENS--.
  // image_style               --NO TOKENS--.
  // language_content_settings --NO TOKENS--.
  // media_type                --NO TOKENS--.
  // node_type                 --NO TOKENS--.
  // rdf_mapping               --NO TOKENS--.
  // responsive_image_style    --NO TOKENS--.
  // rest_resource_config      --NO TOKENS--.
  // search_page               --NO TOKENS--.
  // shortcut_set              --NO TOKENS--.
  // taxonomy_vocabulary       vocabulary                custom.
  // tour                      --NO TOKENS--.
  // user_role                 --NO TOKENS--.
  // view                      view                      custom.
  // workflow                  --NO TOKENS--.
  //
  // The following content entity types are defined in common contrib modules:
  //
  // Content entity type       Token prefix              Defined.
  // -------------------       ------------              -------.
  // foldershare               foldershare               custom.
  //
  // The following configuration entity types are defined in common contrib
  // modules:
  //
  // Config entity type        Token prefix              Defined.
  // ------------------        ------------              -------.
  // login_destination         --NO TOKENS--.
  // pathauto_pattern          array                     custom.
  return [
    // Drupal core entity types where the entity type name DOES NOT
    // match the entity's token prefix.
    'taxonomy_term' => 'term',
    'taxonomy_vocabulary' => 'vocabulary',
  ];
}