-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18cd7be
commit 6f021c3
Showing
7 changed files
with
186 additions
and
1 deletion.
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
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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Website; | ||
|
||
use App\Entity\Event; | ||
use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface; | ||
use Sulu\Bundle\WebsiteBundle\Resolver\TemplateAttributeResolverInterface; | ||
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class EventController extends AbstractController | ||
{ | ||
private WebspaceManagerInterface $webspaceManager; | ||
private RouteRepositoryInterface $routeRepository; | ||
private TemplateAttributeResolverInterface $templateAttributeResolver; | ||
|
||
public function __construct( | ||
WebspaceManagerInterface $webspaceManager, | ||
RouteRepositoryInterface $routeRepository, | ||
TemplateAttributeResolverInterface $templateAttributeResolver | ||
) { | ||
$this->webspaceManager = $webspaceManager; | ||
$this->routeRepository = $routeRepository; | ||
$this->templateAttributeResolver = $templateAttributeResolver; | ||
} | ||
|
||
public function indexAction(Event $event): Response | ||
{ | ||
$parameters = $this->templateAttributeResolver->resolve([ | ||
'event' => $event, | ||
'localizations' => $this->getLocalizationsArrayForEntity($event), | ||
]); | ||
|
||
return $this->render('events/event.html.twig', $parameters); | ||
} | ||
|
||
/** | ||
* @return array<string, array{locale: string, url:string|null}> | ||
*/ | ||
protected function getLocalizationsArrayForEntity(Event $entity): array | ||
{ | ||
$routes = $this->routeRepository->findAllByEntity(Event::class, (string) $entity->getId()); | ||
|
||
$localizations = []; | ||
foreach ($routes as $route) { | ||
$url = $this->webspaceManager->findUrlByResourceLocator( | ||
$route->getPath(), | ||
null, | ||
$route->getLocale() | ||
); | ||
|
||
$localizations[$route->getLocale()] = ['locale' => $route->getLocale(), 'url' => $url]; | ||
} | ||
|
||
return $localizations; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace App\Routing; | ||
|
||
use App\Controller\Website\EventController; | ||
use App\Entity\Event; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sulu\Bundle\RouteBundle\Routing\Defaults\RouteDefaultsProviderInterface; | ||
|
||
class EventRouteDefaultsProvider implements RouteDefaultsProviderInterface | ||
{ | ||
private EntityManagerInterface $entityManager; | ||
|
||
public function __construct( | ||
EntityManagerInterface $entityManager | ||
) { | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getByEntity($entityClass, $id, $locale, $object = null) | ||
{ | ||
return [ | ||
'_controller' => EventController::class . '::indexAction', | ||
'event' => $object ?: $this->entityManager->getRepository(Event::class)->find($id), | ||
]; | ||
} | ||
|
||
public function isPublished($entityClass, $id, $locale) | ||
{ | ||
return true; | ||
} | ||
|
||
public function supports($entityClass) | ||
{ | ||
return Event::class === $entityClass; | ||
} | ||
} |
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,5 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block contentBody %} | ||
<h1>{{ event.name }}</h1> | ||
{% endblock %} |