function commerce_number_pattern_token_info in Commerce Core 8.2
Implements hook_token_info().
File
- modules/
number_pattern/ commerce_number_pattern.module, line 23 - Provides configurable patterns for generating sequential numbers.
Code
function commerce_number_pattern_token_info() {
$time = \Drupal::time()
->getRequestTime();
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
$year = $date_formatter
->format($time, 'custom', 'Y');
$month = $date_formatter
->format($time, 'custom', 'm');
$day = $date_formatter
->format($time, 'custom', 'd');
$info = [];
$info['types']['pattern'] = [
'name' => t('Pattern'),
'needs-data' => 'pattern',
];
$info['tokens']['pattern']['day'] = [
'name' => t('Day'),
'description' => t('The current day, with a leading zero. (%date)', [
'%date' => $day,
]),
];
$info['tokens']['pattern']['month'] = [
'name' => t('Month'),
'description' => t('The current month, with a leading zero. (%date)', [
'%date' => $month,
]),
];
$info['tokens']['pattern']['year'] = [
'name' => t('Year'),
'description' => t('The current year. (%date)', [
'%date' => $year,
]),
];
$info['tokens']['pattern']['date'] = [
'name' => t('Custom date'),
'description' => t('A date in a custom format. See <a href="http://php.net/manual/function.date.php">the PHP documentation</a> for details.'),
'dynamic' => TRUE,
];
$info['tokens']['pattern']['number'] = [
'name' => t('Number'),
'description' => t('The generated sequential number.'),
];
return $info;
}