vendor/ibexa/dashboard/src/bundle/EventSubscriber/PageBuilder/QuickActionsBlockSubscriber.php line 46

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\Bundle\Dashboard\EventSubscriber\PageBuilder;
  8. use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
  9. use Ibexa\Dashboard\Block\QuickActions\ConfigurationProviderInterface;
  10. use Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\BlockRenderEvents;
  11. use Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\Event\PreRenderEvent;
  12. use Psr\Log\LoggerAwareInterface;
  13. use Psr\Log\LoggerAwareTrait;
  14. use Psr\Log\NullLogger;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17. * @internal
  18. */
  19. final class QuickActionsBlockSubscriber implements EventSubscriberInterface, LoggerAwareInterface
  20. {
  21. use LoggerAwareTrait;
  22. private const BLOCK_IDENTIFIER = 'quick_actions';
  23. private ConfigurationProviderInterface $configurationProvider;
  24. public function __construct(ConfigurationProviderInterface $configurationProvider)
  25. {
  26. $this->configurationProvider = $configurationProvider;
  27. $this->logger = new NullLogger();
  28. }
  29. public static function getSubscribedEvents(): array
  30. {
  31. return [
  32. BlockRenderEvents::getBlockPreRenderEventName(self::BLOCK_IDENTIFIER) => [
  33. ['onBlockPreRender', -100],
  34. ],
  35. ];
  36. }
  37. public function onBlockPreRender(PreRenderEvent $event): void
  38. {
  39. /** @var \Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\Twig\TwigRenderRequest $request */
  40. $request = $event->getRenderRequest();
  41. $blockValue = $event->getBlockValue();
  42. $actionsAttribute = $blockValue->getAttribute('actions');
  43. // value format from block select type configuration: create_content,create_product
  44. $actions = null !== $actionsAttribute ? explode(',', $actionsAttribute->getValue()) : [];
  45. $tiles = [];
  46. foreach ($actions as $action) {
  47. try {
  48. $tiles[] = $this->configurationProvider->getConfiguration($action);
  49. } catch (InvalidArgumentException $e) {
  50. $this->logger->warning(
  51. sprintf(
  52. 'Failed to get configuration for configured quick action "%s": %s',
  53. $action,
  54. $e->getMessage()
  55. )
  56. );
  57. }
  58. }
  59. $request->addParameter('tiles', $tiles);
  60. }
  61. }