vendor/ibexa/dashboard/src/lib/EventSubscriber/GenerateDashboardPreviewUrlSubscriber.php line 39

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Dashboard\EventSubscriber;
  8. use Ibexa\Bundle\Dashboard\ViewBuilder\DashboardViewBuilder;
  9. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  10. use Ibexa\Contracts\PageBuilder\Event\GenerateContentPreviewUrlEvent;
  11. use Ibexa\Dashboard\Specification\IsDashboardContentType;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /**
  14. * @internal
  15. */
  16. final class GenerateDashboardPreviewUrlSubscriber implements EventSubscriberInterface
  17. {
  18. private ConfigResolverInterface $configResolver;
  19. public function __construct(ConfigResolverInterface $configResolver)
  20. {
  21. $this->configResolver = $configResolver;
  22. }
  23. public static function getSubscribedEvents(): array
  24. {
  25. return [
  26. GenerateContentPreviewUrlEvent::NAME => ['onGenerateContentPreviewUrl', 0],
  27. ];
  28. }
  29. /**
  30. * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
  31. */
  32. public function onGenerateContentPreviewUrl(GenerateContentPreviewUrlEvent $event): void
  33. {
  34. if (
  35. (new IsDashboardContentType($this->configResolver))->isSatisfiedBy($event->getContent()->getContentType())
  36. ) {
  37. $event->addParameter('viewType', DashboardViewBuilder::DASHBOARD_VIEW_TYPE);
  38. }
  39. }
  40. }