vendor/ibexa/dashboard/src/lib/EventSubscriber/AvailableLayoutsConfigSubscriber.php line 49

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\Contracts\Core\SiteAccess\ConfigResolverInterface;
  9. use Ibexa\Dashboard\Specification\IsDashboardContentType;
  10. use Ibexa\FieldTypePage\Event\AvailableLayoutsConfigEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. /**
  13. * @phpstan-import-type TLayoutDefinition from \Ibexa\FieldTypePage\FieldType\LandingPage\Converter\LayoutDefinitionConverter
  14. */
  15. final class AvailableLayoutsConfigSubscriber implements EventSubscriberInterface
  16. {
  17. private const LAYOUTS_TO_FILTER = [
  18. 'dashboard_one_column',
  19. 'dashboard_two_columns',
  20. 'dashboard_one_third_left',
  21. 'dashboard_one_third_right',
  22. 'dashboard_two_rows_two_columns',
  23. 'dashboard_three_rows_two_columns',
  24. 'dashboard_three_rows_two_columns_2',
  25. 'dashboard_three_columns',
  26. 'dashboard_two_rows_three_columns',
  27. 'dashboard_three_rows_three_columns',
  28. 'dashboard_three_rows_three_columns_2',
  29. ];
  30. private ConfigResolverInterface $configResolver;
  31. public function __construct(ConfigResolverInterface $configResolver)
  32. {
  33. $this->configResolver = $configResolver;
  34. }
  35. public static function getSubscribedEvents(): array
  36. {
  37. return [
  38. AvailableLayoutsConfigEvent::class => ['onAvailableLayoutsConfig', -10],
  39. ];
  40. }
  41. public function onAvailableLayoutsConfig(AvailableLayoutsConfigEvent $event): void
  42. {
  43. $layouts = $event->getLayouts();
  44. $contentType = $event->getContentType();
  45. if ($contentType === null) {
  46. return;
  47. }
  48. if ((new IsDashboardContentType($this->configResolver))->isSatisfiedBy($contentType)) {
  49. return;
  50. }
  51. $filteredLayouts = array_filter(
  52. $layouts,
  53. /**
  54. * @param array<TLayoutDefinition> $layout
  55. */
  56. static function (array $layout): bool {
  57. return !in_array($layout['id'], self::LAYOUTS_TO_FILTER, true);
  58. }
  59. );
  60. $event->setLayouts($filteredLayouts);
  61. }
  62. }