|
- <?php
-
- namespace Lc\CaracoleBundle\Form\Section;
-
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Repository\Section\SectionRepository;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use Lc\CaracoleBundle\Solver\Section\SectionSolver;
- use Lc\SovBundle\Doctrine\EntityManager;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Bridge\Doctrine\Form\Type\EntityType;
- use Symfony\Component\Form\AbstractType;
- use Symfony\Component\Form\Extension\Core\Type\ButtonType;
- use Symfony\Component\Form\Extension\Core\Type\HiddenType;
- use Symfony\Component\Form\Extension\Core\Type\SubmitType;
- use Symfony\Component\Form\FormBuilderInterface;
- use Symfony\Component\OptionsResolver\OptionsResolver;
-
- class SwitchSectionFormType extends AbstractType
- {
- protected EntityManager $em;
- protected TranslatorAdmin $translatorAdmin;
- protected SectionResolver $sectionResolver;
- protected SectionSolver $sectionSolver;
-
- public function __construct(
- EntityManager $em,
- TranslatorAdmin $translatorAdmin,
- SectionResolver $sectionResolver,
- SectionSolver $sectionSolver
- ) {
- $this->em = $em;
- $this->translatorAdmin = $translatorAdmin;
- $this->sectionResolver = $sectionResolver;
- $this->sectionSolver = $sectionSolver;
- }
-
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $section = $options['section'];
- $currentSection = $this->sectionResolver->getCurrent();
-
- $builder->add(
- 'id_section',
- HiddenType::class,
- [
- 'data' => $section ? $section->getId() : null
- ]
- );
-
- $styleButton = '';
- $classButton = 'btn-section';
- if ($section == $currentSection) {
- $classButton .= ' btn-section-current '.$this->sectionSolver->getHtmlClass($currentSection);
- }
-
- $builder->add(
- 'submit',
- SubmitType::class,
- [
- 'label' => $section ? $section->getTitle() : 'Tout afficher',
- 'attr' => [
- 'class' => $classButton,
- 'style' => $styleButton,
- ]
- ]
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults(
- [
- 'section' => null,
- ]
- );
- }
-
- }
|