Create a token to count the number of sent daily
...emails
This commit is contained in:
parent
c722387743
commit
6ba4b80645
4 changed files with 57 additions and 1 deletions
|
@ -46,6 +46,7 @@ module:
|
|||
metatag_open_graph: 0
|
||||
metatag_twitter_cards: 0
|
||||
node: 0
|
||||
opd_daily_emails: 0
|
||||
options: 0
|
||||
page_cache: 0
|
||||
path: 0
|
||||
|
|
|
@ -277,7 +277,7 @@ display:
|
|||
plugin_id: text
|
||||
empty: false
|
||||
content:
|
||||
value: '<p>This is an archive of the 820+ email messages I have sent to <a href="/daily">my daily mailing list</a> since the 12th of August, 2022. Enjoy!</p>'
|
||||
value: '<p>This is an archive of the [opd-daily-emails:email-count] email messages I have sent to <a href="/daily">my daily mailing list</a> since the 12th of August, 2022. Enjoy!</p>'
|
||||
format: basic_html
|
||||
tokenize: false
|
||||
footer: { }
|
||||
|
|
4
modules/opd_daily_emails/opd_daily_emails.info.yml
Normal file
4
modules/opd_daily_emails/opd_daily_emails.info.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
name: Daily Emails
|
||||
type: module
|
||||
core_version_requirement: ^11
|
||||
package: oliverdavies.uk
|
51
modules/opd_daily_emails/opd_daily_emails.module
Normal file
51
modules/opd_daily_emails/opd_daily_emails.module
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?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;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue