<?php
declare(strict_types=1);
namespace Juki\Bundle\AppBundle\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Hitso\Bundle\FormBundle\Event\FormEvent;
use Juki\Bundle\AppBundle\Entity\Dictionary\Shop;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Validator\Constraints\Count;
final class SlideSubscriber implements EventSubscriberInterface
{
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public static function getSubscribedEvents()
{
return [
'slide_form_type.form_init' => 'onSlideFormInit',
];
}
public function onSlideFormInit(FormEvent $event)
{
$builder = $event->getBuilder();
$builder->add(
'mode',
ChoiceType::class,
[
'label' => 'Wizualizacja',
'choices' => [
'jasna' => 'light',
'ciemna' => 'dark',
],
'position' => ['after' => 'target'],
]
);
$builder->add(
'ctaTitle',
TextType::class,
[
'label' => 'Tytuł CTA',
'position' => ['after' => 'url'],
'required' => false,
]
);
$builder->add(
'ctaSubTitle',
TextType::class,
[
'label' => 'Podtytuł CTA',
'position' => ['after' => 'ctaTitle'],
'required' => false,
]
);
$builder->add(
'slideButton',
TextType::class,
[
'label' => 'Tekst przewijania',
'position' => ['after' => 'ctaSubTitle'],
'required' => false,
]
);
$builder->add(
'shops',
ChoiceType::class,
[
'label' => 'Sklep',
'required' => true,
'translation_domain' => 'admin',
'multiple' => false,
'expanded' => false,
'choices' => $this->entityManager->getRepository(Shop::class)->getParentChoices(),
'position' => ['before' => 'target'],
]
);
}
}