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.

38 lines
1.1KB

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