From 122f4a9bec7aa834f1c572fbab7ba8809c76e003 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 10 Jun 2025 20:47:23 +0100 Subject: [PATCH] Add a Presentation bundle class Drupal core issue: https://www.drupal.org/node/2570593 Change record: https://www.drupal.org/node/3191609 --- config/sync/core.extension.yml | 1 + .../opd_presentations.module | 16 +++++++++ .../src/Entity/Presentation.php | 16 +++++++++ .../Entity/PresentationTest.php | 35 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 modules/opd_presentations/opd_presentations.module create mode 100644 modules/opd_presentations/src/Entity/Presentation.php create mode 100644 modules/opd_presentations/tests/src/DrupalTestTraits/Entity/PresentationTest.php diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index dbfe96166..99ac9efc4 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -49,6 +49,7 @@ module: node: 0 opd_daily_emails: 0 opd_podcast: 0 + opd_presentations: 0 options: 0 page_cache: 0 path: 0 diff --git a/modules/opd_presentations/opd_presentations.module b/modules/opd_presentations/opd_presentations.module new file mode 100644 index 000000000..d8662e67d --- /dev/null +++ b/modules/opd_presentations/opd_presentations.module @@ -0,0 +1,16 @@ + $bundles + */ +function opd_presentations_entity_bundle_info_alter(array &$bundles): void { + if (isset($bundles['node'])) { + $bundles['node']['presentation']['class'] = Presentation::class; + } +} diff --git a/modules/opd_presentations/src/Entity/Presentation.php b/modules/opd_presentations/src/Entity/Presentation.php new file mode 100644 index 000000000..218c15f02 --- /dev/null +++ b/modules/opd_presentations/src/Entity/Presentation.php @@ -0,0 +1,16 @@ +get('field_events')->referencedEntities(); + } + +} diff --git a/modules/opd_presentations/tests/src/DrupalTestTraits/Entity/PresentationTest.php b/modules/opd_presentations/tests/src/DrupalTestTraits/Entity/PresentationTest.php new file mode 100644 index 000000000..5f755f3fc --- /dev/null +++ b/modules/opd_presentations/tests/src/DrupalTestTraits/Entity/PresentationTest.php @@ -0,0 +1,35 @@ +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', + ]); + } +}