vendor/ibexa/dashboard/src/lib/EventSubscriber/AvailableBlocksConfigSubscriber.php line 35

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\AvailableBlocksConfigEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. /**
  13. * @phpstan-import-type TBlockDefinition from \Ibexa\FieldTypePage\FieldType\LandingPage\Converter\BlockDefinitionConverter
  14. */
  15. final class AvailableBlocksConfigSubscriber implements EventSubscriberInterface
  16. {
  17. private ConfigResolverInterface $configResolver;
  18. public function __construct(ConfigResolverInterface $configResolver)
  19. {
  20. $this->configResolver = $configResolver;
  21. }
  22. public static function getSubscribedEvents(): array
  23. {
  24. return [
  25. AvailableBlocksConfigEvent::class => ['onAvailableBlocksConfig', -10],
  26. ];
  27. }
  28. public function onAvailableBlocksConfig(AvailableBlocksConfigEvent $event): void
  29. {
  30. $blocks = $event->getBlocks();
  31. $contentType = $event->getContentType();
  32. if ($contentType === null) {
  33. return;
  34. }
  35. if ((new IsDashboardContentType($this->configResolver))->isSatisfiedBy($contentType)) {
  36. return;
  37. }
  38. $filteredBlocks = array_filter(
  39. $blocks,
  40. /**
  41. * @param array<TBlockDefinition> $block
  42. */
  43. static function (array $block): bool {
  44. return $block['category'] !== 'Dashboard';
  45. }
  46. );
  47. $event->setBlocks($filteredBlocks);
  48. }
  49. }