5b: Throw an Exception is a non-article is wrapped
Within the article wrapper, let’s check that the node is an article, otherwise thrown the Exception as expected.
This commit is contained in:
parent
76172f4667
commit
3ecca5ad0c
1 changed files with 11 additions and 0 deletions
|
@ -9,6 +9,8 @@ class ArticleWrapper {
|
|||
private $article;
|
||||
|
||||
public function __construct(NodeInterface $node) {
|
||||
$this->verifyNodeType($node);
|
||||
|
||||
$this->article = $node;
|
||||
}
|
||||
|
||||
|
@ -16,4 +18,13 @@ class ArticleWrapper {
|
|||
return $this->article;
|
||||
}
|
||||
|
||||
private function verifyNodeType(NodeInterface $node): void {
|
||||
if ($node->bundle() != 'article') {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'%s is not an article',
|
||||
$node->bundle()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue