oliverdavies.uk/modules/opd_daily_emails/opd_daily_emails.module

51 lines
994 B
PHP

<?php
declare(strict_types=1);
use Drupal\Core\Render\BubbleableMetadata;
/**
* Implements hook_token_info().
*/
function opd_daily_emails_token_info(): array {
$tokens = [];
$type = [
'description' => t('Tokens related to daily emails.'),
'name' => t('Daily emails'),
];
$tokens['email-count'] = [
'description' => t('The number of sent daily emails.'),
'name' => t('Daily email count'),
];
return [
'tokens' => [
'opd-daily-emails' => $tokens,
],
'types' => [
'opd-daily-emails' => $type,
],
];
}
/**
* Implements hook_tokens().
*/
function opd_daily_emails_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleableMetadata) : array {
$replacements = [];
if ($type === 'opd-daily-emails') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'email-count':
$replacements[$original] = 822;
break;
}
}
}
return $replacements;
}