vendor/ibexa/connector-dam/src/lib/Event/AddSearchFormEventSubscriber.php line 37

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\Connector\Dam\Event;
  8. use Ibexa\AdminUi\Tab\Event\TabEvents;
  9. use Ibexa\AdminUi\Tab\Event\TabGroupEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\Form\FormFactoryInterface;
  12. class AddSearchFormEventSubscriber implements EventSubscriberInterface
  13. {
  14. private FormFactoryInterface $formFactory;
  15. private string $searchFormType;
  16. public function __construct(
  17. FormFactoryInterface $formFactory,
  18. string $searchFormType
  19. ) {
  20. $this->formFactory = $formFactory;
  21. $this->searchFormType = $searchFormType;
  22. }
  23. public static function getSubscribedEvents(): array
  24. {
  25. return [
  26. TabEvents::TAB_GROUP_PRE_RENDER => 'addSearchForm',
  27. ];
  28. }
  29. public function addSearchForm(TabGroupEvent $event): void
  30. {
  31. if ($event->getData()->getIdentifier() !== 'connector-dam-search') {
  32. return;
  33. }
  34. $parameters = $event->getParameters();
  35. $parameters['form'] = $this->formFactory->createNamed(
  36. 'main-dam-search-source',
  37. $this->searchFormType,
  38. )->createView();
  39. $event->setParameters($parameters);
  40. }
  41. }