Make the email count dynamic based on the number
...of daily email nodes
This commit is contained in:
parent
6ba4b80645
commit
c48f8acd4a
9 changed files with 5666 additions and 5 deletions
|
@ -34,11 +34,12 @@
|
|||
"config": {
|
||||
"allow-plugins": {
|
||||
"composer/installers": true,
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||
"drupal/core-composer-scaffold": true,
|
||||
"drupal/core-project-message": true,
|
||||
"php-http/discovery": true,
|
||||
"phpstan/extension-installer": true,
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||
"php-http/discovery": true
|
||||
"tbachert/spi": true
|
||||
},
|
||||
"sort-packages": true
|
||||
},
|
||||
|
@ -116,5 +117,8 @@
|
|||
"test": [
|
||||
"composer validate --strict"
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"drupal/core-dev": "^11.1"
|
||||
}
|
||||
}
|
||||
|
|
5529
composer.lock
generated
5529
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,7 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository;
|
||||
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
|
@ -40,7 +41,9 @@ function opd_daily_emails_tokens($type, $tokens, array $data, array $options, Bu
|
|||
foreach ($tokens as $name => $original) {
|
||||
switch ($name) {
|
||||
case 'email-count':
|
||||
$replacements[$original] = 822;
|
||||
$dailyEmailRepository = \Drupal::service(DailyEmailNodeRepository::class);
|
||||
|
||||
$replacements[$original] = count($dailyEmailRepository->getAll());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
3
modules/opd_daily_emails/opd_daily_emails.services.yml
Normal file
3
modules/opd_daily_emails/opd_daily_emails.services.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
services:
|
||||
Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository:
|
||||
autowire: true
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_daily_emails\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
final class DailyEmailNodeRepository implements DailyEmailRepositoryInterface {
|
||||
|
||||
public function __construct(
|
||||
public readonly EntityTypeManagerInterface $entityTypeManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getAll(): array {
|
||||
$query = $this->entityTypeManager
|
||||
->getStorage('node')
|
||||
->getQuery();
|
||||
|
||||
// TODO: add condition for published status. Only return published nodes.
|
||||
$query->condition('type', 'daily_email');
|
||||
|
||||
$query->accessCheck(TRUE);
|
||||
|
||||
$result = $query->execute();
|
||||
|
||||
// TODO: this returns a list of node IDs. Load and return the nodes.
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_daily_emails\Repository;
|
||||
|
||||
interface DailyEmailRepositoryInterface {
|
||||
|
||||
public function getAll(): array;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_daily_emails\Kernel\Repository;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailRepositoryInterface;
|
||||
|
||||
final class DailyEmailNodeRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
use NodeCreationTrait;
|
||||
|
||||
public static $modules = [
|
||||
'node',
|
||||
'opd_daily_emails',
|
||||
];
|
||||
|
||||
/**
|
||||
* @testdox Get all daily emails
|
||||
*/
|
||||
public function test_get_all(): void {
|
||||
$this->createNode([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'type' => 'daily_email',
|
||||
]);
|
||||
|
||||
$repository = $this->container->get(DailyEmailNodeRepository::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
actual: $repository,
|
||||
expected: DailyEmailRepositoryInterface::class,
|
||||
);
|
||||
|
||||
$this->assertCount(
|
||||
expectedCount: 1,
|
||||
haystack: $repository->getAll(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
37
phpunit.xml.dist
Normal file
37
phpunit.xml.dist
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
bootstrap="web/core/tests/bootstrap.php"
|
||||
colors="true"
|
||||
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
beStrictAboutChangesToGlobalState="true"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
displayDetailsOnTestsThatTriggerErrors="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
cacheResult="false"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
|
||||
cacheDirectory=".phpunit.cache">
|
||||
<php>
|
||||
<ini name="error_reporting" value="32767"/>
|
||||
<ini name="memory_limit" value="-1"/>
|
||||
<env name="SIMPLETEST_BASE_URL" value=""/>
|
||||
<env name="SIMPLETEST_DB" value="sqlite://localhost//dev/shm/testing.sqlite"/>
|
||||
<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>
|
||||
<env name="MINK_DRIVER_CLASS" value=""/>
|
||||
<env name="MINK_DRIVER_ARGS" value=""/>
|
||||
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=""/>
|
||||
</php>
|
||||
<extensions>
|
||||
<bootstrap class="Drupal\TestTools\Extension\HtmlLogging\HtmlOutputLogger">
|
||||
<parameter name="outputDirectory" value="sites/simpletest/browser_output"/>
|
||||
<parameter name="verbose" value="true"/>
|
||||
</bootstrap>
|
||||
</extensions>
|
||||
<testsuites>
|
||||
<testsuite name="Module tests">
|
||||
<directory>modules/*</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
2
todo.txt
2
todo.txt
|
@ -34,3 +34,5 @@ Other content:
|
|||
- Migrate old blog posts.
|
||||
- Migrate basic pages.
|
||||
|
||||
`grep -rnE TODO modules themes`
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue