Add a Presentation bundle class
Drupal core issue: https://www.drupal.org/node/2570593 Change record: https://www.drupal.org/node/3191609
This commit is contained in:
parent
7e45664407
commit
122f4a9bec
4 changed files with 68 additions and 0 deletions
|
@ -49,6 +49,7 @@ module:
|
|||
node: 0
|
||||
opd_daily_emails: 0
|
||||
opd_podcast: 0
|
||||
opd_presentations: 0
|
||||
options: 0
|
||||
page_cache: 0
|
||||
path: 0
|
||||
|
|
16
modules/opd_presentations/opd_presentations.module
Normal file
16
modules/opd_presentations/opd_presentations.module
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Drupal\opd_presentations\Entity\Presentation;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info_alter().
|
||||
*
|
||||
* @param array<non-empty-string, array{class: non-empty-string}> $bundles
|
||||
*/
|
||||
function opd_presentations_entity_bundle_info_alter(array &$bundles): void {
|
||||
if (isset($bundles['node'])) {
|
||||
$bundles['node']['presentation']['class'] = Presentation::class;
|
||||
}
|
||||
}
|
16
modules/opd_presentations/src/Entity/Presentation.php
Normal file
16
modules/opd_presentations/src/Entity/Presentation.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations\Entity;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
final class Presentation extends Node implements NodeInterface {
|
||||
|
||||
public function getPastEvents(): array {
|
||||
return $this->get('field_events')->referencedEntities();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations\DrupalTestTraits\Entity;
|
||||
|
||||
use Drupal\paragraphs\Entity\Paragraph;
|
||||
use Drupal\opd_presentations\Entity\Presentation;
|
||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||
|
||||
final class PresentationTest extends ExistingSiteBase {
|
||||
|
||||
public function test_getting_past_events(): void {
|
||||
$presentation = $this->createPresentation(
|
||||
events: [
|
||||
Paragraph::create(['type' => 'event']),
|
||||
],
|
||||
);
|
||||
|
||||
$this->assertCount(
|
||||
expectedCount: 1,
|
||||
haystack: $presentation->getPastEvents(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ParagraphInterface[] $events
|
||||
*/
|
||||
private function createPresentation(array $events): Presentation {
|
||||
return $this->createNode([
|
||||
'field_events' => $events,
|
||||
'type' => 'presentation',
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue