Move all files to tome/
This commit is contained in:
parent
5675bcfc36
commit
674daab35b
2874 changed files with 0 additions and 0 deletions
103
tome/modules/opd_daily_emails/opd_daily_emails.module
Normal file
103
tome/modules/opd_daily_emails/opd_daily_emails.module
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\opd_daily_emails\Action\AddRandomCtaToDailyEmail;
|
||||
use Drupal\opd_daily_emails\DailyEmail;
|
||||
use Drupal\opd_daily_emails\DailyEmailNodeRepository;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info_alter().
|
||||
*
|
||||
* @param array<non-empty-string, array{class: non-empty-string}> $bundles
|
||||
*/
|
||||
function opd_daily_emails_entity_bundle_info_alter(array &$bundles): void {
|
||||
if (isset($bundles['node'])) {
|
||||
$bundles['node'][DailyEmail::NODE_TYPE]['class'] = DailyEmail::class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_presave().
|
||||
*/
|
||||
function opd_daily_emails_entity_presave(Drupal\Core\Entity\EntityInterface $entity): void {
|
||||
if (!$entity instanceof DailyEmail) {
|
||||
return;
|
||||
}
|
||||
|
||||
\Drupal::service(AddRandomCtaToDailyEmail::class)($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*
|
||||
* @param array{'#action': string, '#attributes': array<non-empty-string, mixed>} $form
|
||||
*/
|
||||
function opd_daily_emails_form_opd_daily_emails_kit_subscription_form_alter(array &$form): void {
|
||||
$form['#action'] = 'https://app.convertkit.com/forms/3546728/subscriptions';
|
||||
|
||||
$form['#attributes']['data-format'] = 'inline';
|
||||
$form['#attributes']['data-sv-form'] = '3546728';
|
||||
$form['#attributes']['data-uid'] = 'f0c1d2b57f';
|
||||
$form['#attributes']['data-version'] = 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
*
|
||||
* @return array{tokens: array{opd-daily-emails: array{description: TranslatableMarkup, name: TranslatableMarkup}[]}, types: array{opd-daily-emails: array{description: TranslatableMarkup, name: TranslatableMarkup}}}
|
||||
*/
|
||||
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().
|
||||
*
|
||||
* @param array<non-empty-string, non-empty-string> $tokens
|
||||
* @param array<non-empty-string, mixed> $data
|
||||
* @param array<non-empty-string, mixed> $options
|
||||
*
|
||||
* @return array<non-empty-string, mixed>
|
||||
*/
|
||||
function opd_daily_emails_tokens(string $type, array $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;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue