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; }