You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3KB

  1. <?php
  2. namespace Lc\SovBundle\Field;
  3. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
  5. use Lc\SovBundle\Field\Filter\BooleanFilter;
  6. use Lc\SovBundle\Field\Filter\CheckboxFilter;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. /**
  9. * @author La clic ! <contact@laclic.fr>
  10. */
  11. final class StatusField implements FieldInterface
  12. {
  13. use FieldTrait;
  14. public static function new(string $propertyName, ?string $label = null, bool $templateToggle = true): self
  15. {
  16. $field = (new self())
  17. ->setProperty($propertyName)
  18. ->setLabel($label)
  19. ->setFormType(ChoiceType::class)
  20. ->setFormTypeOption('expanded', true)
  21. ->setFormTypeOption('multiple', false)
  22. ->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0])
  23. ->setFormTypeOption('placeholder', false)
  24. ->setCustomOption('toggle_label', 'En ligne')
  25. ->setCustomOption('filter_fqcn', CheckboxFilter::class);
  26. $template = 'toggle.html.twig';
  27. if (!$templateToggle) {
  28. $template = 'status.html.twig';
  29. }
  30. $field->setTemplatePath('@LcSov/adminlte/crud/field/' . $template);
  31. return $field;
  32. }
  33. }