From 0c6fa6e60f5a5fa3755c7c8c0cf0868f9ed9491f Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 14 Nov 2020 12:52:22 +0000 Subject: [PATCH] Throw an Exception if it is the wrong type --- web/modules/custom/my_module/src/Entity/Post.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/modules/custom/my_module/src/Entity/Post.php b/web/modules/custom/my_module/src/Entity/Post.php index 5cd63da..83e9aac 100644 --- a/web/modules/custom/my_module/src/Entity/Post.php +++ b/web/modules/custom/my_module/src/Entity/Post.php @@ -9,6 +9,10 @@ class Post { private $node; public function __construct(NodeInterface $node) { + if ($node->bundle() != 'article') { + throw new \InvalidArgumentException(); + } + $this->node = $node; }