-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event_selection and single_event_selection content-type
- Loading branch information
1 parent
cd4fe57
commit b0f648b
Showing
6 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Content\Type; | ||
|
||
use App\Entity\Event; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sulu\Component\Content\Compat\PropertyInterface; | ||
use Sulu\Component\Content\SimpleContentType; | ||
|
||
class EventSelection extends SimpleContentType | ||
{ | ||
protected EntityManagerInterface $entityManager; | ||
|
||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
|
||
parent::__construct('event_selection', []); | ||
} | ||
|
||
/** | ||
* @return Event[] | ||
*/ | ||
public function getContentData(PropertyInterface $property): array | ||
{ | ||
$ids = $property->getValue(); | ||
|
||
if (empty($ids)) { | ||
return []; | ||
} | ||
|
||
$events = $this->entityManager->getRepository(Event::class)->findBy(['id' => $ids]); | ||
|
||
$idPositions = array_flip($ids); | ||
usort($events, function (Event $a, Event $b) use ($idPositions) { | ||
return $idPositions[$a->getId()] - $idPositions[$b->getId()]; | ||
}); | ||
|
||
return $events; | ||
} | ||
|
||
/** | ||
* @return array<string, array<int>|null> | ||
*/ | ||
public function getViewData(PropertyInterface $property): array | ||
{ | ||
return [ | ||
'ids' => $property->getValue(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Content\Type; | ||
|
||
use App\Entity\Event; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sulu\Component\Content\Compat\PropertyInterface; | ||
use Sulu\Component\Content\SimpleContentType; | ||
|
||
class SingleEventSelection extends SimpleContentType | ||
{ | ||
protected EntityManagerInterface $entityManager; | ||
|
||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
|
||
parent::__construct('single_event_selection', null); | ||
} | ||
|
||
public function getContentData(PropertyInterface $property): ?Event | ||
{ | ||
$id = $property->getValue(); | ||
|
||
if (empty($id)) { | ||
return null; | ||
} | ||
|
||
return $this->entityManager->getRepository(Event::class)->find($id); | ||
} | ||
|
||
/** | ||
* @return array<string, int|null> | ||
*/ | ||
public function getViewData(PropertyInterface $property): array | ||
{ | ||
return [ | ||
'id' => $property->getValue(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters