57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Drupal\Core\Render\BubbleableMetadata;
|
|
use Drupal\opd_daily_emails\Collection\DailyEmailCollection;
|
|
use Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository;
|
|
|
|
/**
|
|
* 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':
|
|
$dailyEmailRepository = \Drupal::service(DailyEmailNodeRepository::class);
|
|
|
|
$dailyEmails = $dailyEmailRepository->getAll();
|
|
|
|
$replacements[$original] = $dailyEmails->count();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $replacements;
|
|
}
|
|
|