function system_token_info in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/system.tokens.inc \system_token_info()
- 7 modules/system/system.tokens.inc \system_token_info()
Implements hook_token_info().
File
- core/
modules/ system/ system.tokens.inc, line 17 - Builds placeholder replacement tokens system-wide data.
Code
function system_token_info() {
$types['site'] = [
'name' => t("Site information"),
'description' => t("Tokens for site-wide settings and other global information."),
];
$types['date'] = [
'name' => t("Dates"),
'description' => t("Tokens related to times and dates."),
];
// Site-wide global tokens.
$site['name'] = [
'name' => t("Name"),
'description' => t("The name of the site."),
];
$site['slogan'] = [
'name' => t("Slogan"),
'description' => t("The slogan of the site."),
];
$site['mail'] = [
'name' => t("Email"),
'description' => t("The administrative email address for the site."),
];
$site['url'] = [
'name' => t("URL"),
'description' => t("The URL of the site's front page."),
];
$site['url-brief'] = [
'name' => t("URL (brief)"),
'description' => t("The URL of the site's front page without the protocol."),
];
$site['login-url'] = [
'name' => t("Login page"),
'description' => t("The URL of the site's login page."),
];
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
// Date related tokens.
$date['short'] = [
'name' => t("Short format"),
'description' => t("A date in 'short' format. (%date)", [
'%date' => $date_formatter
->format(REQUEST_TIME, 'short'),
]),
];
$date['medium'] = [
'name' => t("Medium format"),
'description' => t("A date in 'medium' format. (%date)", [
'%date' => $date_formatter
->format(REQUEST_TIME, 'medium'),
]),
];
$date['long'] = [
'name' => t("Long format"),
'description' => t("A date in 'long' format. (%date)", [
'%date' => $date_formatter
->format(REQUEST_TIME, 'long'),
]),
];
$date['custom'] = [
'name' => t("Custom format"),
'description' => t('A date in a custom format. See <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters">the PHP documentation</a> for details.'),
];
$date['since'] = [
'name' => t("Time-since"),
'description' => t("A date in 'time-since' format. (%date)", [
'%date' => $date_formatter
->formatTimeDiffSince(REQUEST_TIME - 360),
]),
];
$date['raw'] = [
'name' => t("Raw timestamp"),
'description' => t("A date in UNIX timestamp format (%date)", [
'%date' => REQUEST_TIME,
]),
];
return [
'types' => $types,
'tokens' => [
'site' => $site,
'date' => $date,
],
];
}