Refactor
Try a different way of naming and grouping classes.
This commit is contained in:
parent
52c1b33711
commit
6b6b362a49
15 changed files with 111 additions and 59 deletions
|
@ -2,8 +2,8 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Drupal\opd_presentations\Entity\Event;
|
||||
use Drupal\opd_presentations\Entity\Presentation;
|
||||
use Drupal\opd_presentations\Event;
|
||||
use Drupal\opd_presentations\Presentation;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info_alter().
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations\Entity;
|
||||
namespace Drupal\opd_presentations;
|
||||
|
||||
use Drupal\paragraphs\Entity\Paragraph;
|
||||
use Drupal\paragraphs\ParagraphInterface;
|
|
@ -2,19 +2,17 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations\Collection;
|
||||
|
||||
use Drupal\opd_presentations\Entity\Event;
|
||||
namespace Drupal\opd_presentations;
|
||||
|
||||
/**
|
||||
* @implements \IteratorAggregate<Event>
|
||||
*/
|
||||
readonly final class EventCollection implements \IteratorAggregate {
|
||||
readonly final class Events implements \IteratorAggregate {
|
||||
|
||||
/**
|
||||
* @param Event[] $events
|
||||
*/
|
||||
public function __construct(private array $events) {
|
||||
private function __construct(private array $events) {
|
||||
}
|
||||
|
||||
public function first(): Event {
|
||||
|
@ -25,4 +23,11 @@ readonly final class EventCollection implements \IteratorAggregate {
|
|||
return new \ArrayIterator($this->events);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event[] $events
|
||||
*/
|
||||
public static function new(array $events): self {
|
||||
return new self($events);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,24 +2,22 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_presentations\Entity;
|
||||
namespace Drupal\opd_presentations;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\opd_presentations\Collection\EventCollection;
|
||||
use Drupal\opd_presentations\Entity\Event;
|
||||
|
||||
final class Presentation extends Node implements NodeInterface {
|
||||
|
||||
public const NODE_TYPE = 'presentation';
|
||||
|
||||
public function getPastEvents(): EventCollection {
|
||||
public function getPastEvents(): Events {
|
||||
$events = $this->get('field_events')->referencedEntities();
|
||||
|
||||
$today = (new DrupalDateTime('today'))->format('U');
|
||||
|
||||
return new EventCollection(array_filter(
|
||||
return Events::new(array_filter(
|
||||
array: $events,
|
||||
callback: fn (Event $event): bool => $event->getEventDate() < $today,
|
||||
));
|
|
@ -7,8 +7,8 @@ namespace Drupal\Tests\opd_presentations\Traits;
|
|||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\ctools\Testing\EntityCreationTrait;
|
||||
use Drupal\opd_presentations\Entity\Event;
|
||||
use Drupal\opd_presentations\Entity\Presentation;
|
||||
use Drupal\opd_presentations\Event;
|
||||
use Drupal\opd_presentations\Presentation;
|
||||
|
||||
trait PresentationCreationTrait {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue