Add PresentationBuilder
This commit is contained in:
parent
a2fc812ddb
commit
9148ec5a65
3 changed files with 77 additions and 47 deletions
40
modules/opd_presentations/src/PresentationBuilder.php
Normal file
40
modules/opd_presentations/src/PresentationBuilder.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations;
|
||||
|
||||
final class PresentationBuilder {
|
||||
|
||||
public function __construct(
|
||||
private string $title,
|
||||
private array $events = [],
|
||||
private bool $isPublished = TRUE,
|
||||
) {
|
||||
}
|
||||
|
||||
public function build(): Presentation {
|
||||
return Presentation::create([
|
||||
'field_events' => $this->events,
|
||||
'status' => $this->isPublished,
|
||||
'title' => $this->title,
|
||||
]);
|
||||
}
|
||||
|
||||
public function setEvents(array $events): self {
|
||||
$this->events = $events;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPublished(bool $isPublished = TRUE): self {
|
||||
$this->isPublished = $isPublished;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function create(string $title): self {
|
||||
return new self($title);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue