1 system.tokens.inc system_token_info()

Implements hook_token_info().

File

core/modules/system/system.tokens.inc, line 10
Builds placeholder replacement tokens system-wide data.

Code

function system_token_info() {
  $types['site'] = array(
    'name' => t('Site information'),
    'description' => t('Tokens for site-wide settings and other global information.'),
  );
  $types['current-page'] = array(
    'name' => t('Current page'),
    'description' => t('Tokens related to the current page request.'),
  );
  $types['current-date'] = array(
    'name' => t('Current date'),
    'description' => t('Tokens related to the current date and time.'),
    'type' => 'date',
  );
  $types['date'] = array(
    'name' => t('Dates'),
    'description' => t('Tokens related to times and dates.'),
    'needs-data' => 'date',
  );
  $types['file'] = array(
    'name' => t('Files'),
    'description' => t('Tokens related to uploaded files.'),
    'needs-data' => 'file',
  );
  $types['url'] = array(
    'name' => t('URL'),
    'description' => t('Tokens related to URLs.'),
    'needs-data' => 'path',
  );
  $types['array'] = array(
    'name' => t('Array'),
    'description' => t('Tokens related to arrays of strings.'),
    'needs-data' => 'array',
  );

  // Site-wide global tokens.
  $site['name'] = array(
    'name' => t('Name'),
    'description' => t('The name of the site.'),
  );
  $site['slogan'] = array(
    'name' => t('Slogan'),
    'description' => t('The slogan of the site.'),
  );
  $site['mail'] = array(
    'name' => t('Email'),
    'description' => t('The administrative email address for the site.'),
  );
  $site['url'] = array(
    'name' => t('URL'),
    'description' => t("The URL of the site's home page."),
    'type' => 'url',
  );
  // @deprecated: Replaced by url:brief.
  $site['url-brief'] = array(
    'name' => t('URL (brief)'),
    'description' => t("The URL of the site's home page without the protocol."),
    'deprecated' => TRUE,
  );
  $site['login-url'] = array(
    'name' => t("Login page"),
    'description' => t("The URL of the site's login page."),
    'type' => 'url',
  );

  // Current page tokens.
  $current_page['title'] = array(
    'name' => t('Title'),
    'description' => t('The title of the current page.'),
  );
  $current_page['url'] = array(
    'name' => t('URL'),
    'description' => t('The URL of the current page.'),
    'type' => 'url',
  );
  $current_page['page-number'] = array(
    'name' => t('Page number'),
    'description' => t('The page number of the current page when viewing paged lists.'),
  );
  $current_page['query'] = array(
    'name' => t('Query string value'),
    'description' => t('The value of a specific query string field of the current page.'),
    'dynamic' => TRUE,
  );

  // URL tokens.
  $url['path'] = array(
    'name' => t('Path'),
    'description' => t('The path component of the URL.'),
  );
  $url['relative'] = array(
    'name' => t('Relative URL'),
    'description' => t('The relative URL.'),
  );
  $url['absolute'] = array(
    'name' => t('Absolute URL'),
    'description' => t('The absolute URL.'),
  );
  $url['brief'] = array(
    'name' => t('Brief URL'),
    'description' => t('The URL without the protocol and trailing backslash.'),
  );
  $url['unaliased'] = array(
    'name' => t('Unaliased URL'),
    'description' => t('The unaliased URL.'),
    'type' => 'url',
  );
  $url['args'] = array(
    'name' => t('Arguments'),
    'description' => t("The specific argument of the current page (e.g. 'arg:1' on the page 'node/1' returns '1')."),
    'type' => 'array',
  );

  // Menu link tokens.
  $menu_link['mlid'] = array(
    'name' => t('Link ID'),
    'description' => t('The unique ID of the menu link.'),
  );
  $menu_link['title'] = array(
    'name' => t('Title'),
    'description' => t('The title of the menu link.'),
  );
  $menu_link['url'] = array(
    'name' => t('URL'),
    'description' => t('The URL of the menu link.'),
    'type' => 'url',
  );
  $menu_link['parent'] = array(
    'name' => t('Parent'),
    'description' => t("The menu link's parent."),
    'type' => 'menu-link',
  );
  $menu_link['parents'] = array(
    'name' => t('Parents'),
    'description' => t("An array of all the menu link's parents, starting with the root."),
    'type' => 'array',
  );
  $menu_link['root'] = array(
    'name' => t('Root'),
    'description' => t("The menu link's root."),
    'type' => 'menu-link',
  );

  // Array tokens.
  $array['first'] = array(
    'name' => t('First'),
    'description' => t('The first element of the array.'),
  );
  $array['last'] = array(
    'name' => t('Last'),
    'description' => t('The last element of the array.'),
  );
  $array['count'] = array(
    'name' => t('Count'),
    'description' => t('The number of elements in the array.'),
  );
  $array['reversed'] = array(
    'name' => t('Reversed'),
    'description' => t('The array reversed.'),
    'type' => 'array',
  );
  $array['keys'] = array(
    'name' => t('Keys'),
    'description' => t('The array of keys of the array.'),
    'type' => 'array',
  );
  $array['join'] = array(
    'name' => t('Imploded'),
    'description' => t('The values of the array joined together with a custom string in-between each value.'),
    'dynamic' => TRUE,
  );
  $array['value'] = array(
    'name' => t('Value'),
    'description' => t('The specific value of the array.'),
    'dynamic' => TRUE,
  );

  // Date related tokens.
  $date_format_types = system_get_date_formats();
  foreach ($date_format_types as $machine_name => $date_format_type_info) {
    if (!isset($date_format_type_info['hidden']) || $date_format_type_info['hidden'] == FALSE) {
      $date[$machine_name] = array(
        'name' => check_plain($date_format_type_info['label']),
        'description' => t("A date in '@type' format. (%date)", array('@type' => $machine_name, '%date' => format_date(REQUEST_TIME, $machine_name))),
      );
    }
  }
  $date['custom'] = array(
    'name' => t('Custom format'),
    'description' => t('A date in a custom format. See the <a href="@url" target="_blank">PHP manual</a> for available options.', array('@url' => 'https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters')),
    'dynamic' => TRUE,
  );
  $date['since'] = array(
    'name' => t('Time-since'),
    'description' => t("A date in 'time-since' format. (%date)", array('%date' => format_interval(REQUEST_TIME - 360, 2))),
  );
  $date['raw'] = array(
    'name' => t('Raw timestamp'),
    'description' => t("A date in UNIX timestamp format (%date)", array('%date' => REQUEST_TIME)),
  );

  // File related tokens.
  $file['fid'] = array(
    'name' => t('File ID'),
    'description' => t('The unique ID of the uploaded file.'),
  );
  $file['name'] = array(
    'name' => t('File name'),
    'description' => t('The name of the file on disk.'),
  );
  $file['basename'] = array(
    'name' => t('Base name'),
    'description' => t('The base name of the file.'),
  );
  $file['path'] = array(
    'name' => t('Path'),
    'description' => t('The location of the file relative to the Backdrop root.'),
  );
  $file['url'] = array(
    'name' => t('URL'),
    'description' => t('The web-accessible URL for the file.'),
  );
  $file['mime'] = array(
    'name' => t('MIME type'),
    'description' => t('The MIME type of the file.'),
  );
  $file['extension'] = array(
    'name' => t('Extension'),
    'description' => t('The extension of the file.'),
  );
  $file['size'] = array(
    'name' => t('File size'),
    'description' => t('The size of the file.'),
  );
  $file['size-raw'] = array(
    'name' => t('File byte size'),
    'description' => t('The size of the file, in bytes.'),
  );
  $file['timestamp'] = array(
    'name' => t('Timestamp'),
    'description' => t('The date the file was most recently changed.'),
    'type' => 'date',
  );
  $file['owner'] = array(
    'name' => t('Owner'),
    'description' => t('The user who originally uploaded the file.'),
    'type' => 'user',
  );

  return array(
    'types' => $types,
    'tokens' => array(
      'site' => $site,
      'current-page' => $current_page,
      'url' => $url,
      'menu-link' => $menu_link,
      'array' => $array,
      'date' => $date,
      'file' => $file,
    ),
  );
}