function NodeTokensHooks::tokenInfo

Implements hook_token_info().

Attributes

#[Hook('token_info')]

File

core/modules/node/src/Hook/NodeTokensHooks.php, line 22

Class

NodeTokensHooks
Hook implementations for node.

Namespace

Drupal\node\Hook

Code

public function tokenInfo() : array {
  $type = [
    'name' => $this->t('Nodes'),
    'description' => $this->t('Tokens related to individual content items, or "nodes".'),
    'needs-data' => 'node',
  ];
  // Core tokens for nodes.
  $node['nid'] = [
    'name' => $this->t("Content ID"),
    'description' => $this->t('The unique ID of the content item, or "node".'),
  ];
  $node['uuid'] = [
    'name' => $this->t('UUID'),
    'description' => $this->t('The UUID of the content item, or "node".'),
  ];
  $node['vid'] = [
    'name' => $this->t("Revision ID"),
    'description' => $this->t("The unique ID of the node's latest revision."),
  ];
  $node['type'] = [
    'name' => $this->t("Content type"),
  ];
  $node['type-name'] = [
    'name' => $this->t("Content type name"),
    'description' => $this->t("The human-readable name of the node type."),
  ];
  $node['title'] = [
    'name' => $this->t("Title"),
  ];
  $node['body'] = [
    'name' => $this->t("Body"),
    'description' => $this->t("The main body text of the node."),
  ];
  $node['summary'] = [
    'name' => $this->t("Summary"),
    'description' => $this->t("The summary of the node's main body text."),
  ];
  $node['langcode'] = [
    'name' => $this->t('Language code'),
    'description' => $this->t('The language code of the language the node is written in.'),
  ];
  $node['published_status'] = [
    'name' => $this->t('Published'),
    'description' => $this->t('The publication status of the node ("Published" or "Unpublished").'),
  ];
  $node['url'] = [
    'name' => $this->t("URL"),
    'description' => $this->t("The URL of the node."),
  ];
  $node['edit-url'] = [
    'name' => $this->t("Edit URL"),
    'description' => $this->t("The URL of the node's edit page."),
  ];
  // Chained tokens for nodes.
  $node['created'] = [
    'name' => $this->t("Date created"),
    'type' => 'date',
  ];
  $node['changed'] = [
    'name' => $this->t("Date changed"),
    'description' => $this->t("The date the node was most recently updated."),
    'type' => 'date',
  ];
  $node['author'] = [
    'name' => $this->t("Author"),
    'type' => 'user',
  ];
  return [
    'types' => [
      'node' => $type,
    ],
    'tokens' => [
      'node' => $node,
    ],
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.