<?php | |||||
namespace Lc\SovBundle\Field; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait; | |||||
use Lc\SovBundle\Form\Type\FileManagerType; | |||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||||
/** | |||||
* @author La clic ! <contact@laclic.fr> | |||||
*/ | |||||
final class BooleanField implements FieldInterface | |||||
{ | |||||
use FieldTrait; | |||||
public static function new(string $propertyName, ?string $label = null): self | |||||
{ | |||||
return (new self()) | |||||
->setProperty($propertyName) | |||||
->setLabel($label) | |||||
->setTemplatePath('@LcSov/adminlte/crud/field/toggle.html.twig') | |||||
->setFormType(ChoiceType::class) | |||||
->setFormTypeOption('expanded', false) | |||||
->setFormTypeOption('multiple', false) | |||||
->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0]); | |||||
} | |||||
} |
{ | { | ||||
use FieldTrait; | use FieldTrait; | ||||
public static function new(string $propertyName, ?string $label = null): self | |||||
public static function new(string $propertyName, ?string $label = null, bool $templateToggle = true): self | |||||
{ | { | ||||
return (new self()) | |||||
$field = (new self()) | |||||
->setProperty($propertyName) | ->setProperty($propertyName) | ||||
->setLabel($label) | ->setLabel($label) | ||||
->setTemplatePath('@LcSov/adminlte/crud/field/status.html.twig') | |||||
->setFormType(ChoiceType::class) | ->setFormType(ChoiceType::class) | ||||
->setFormTypeOption('expanded', false) | ->setFormTypeOption('expanded', false) | ||||
->setFormTypeOption('multiple', false) | ->setFormTypeOption('multiple', false) | ||||
->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0]); | ->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0]); | ||||
$template = 'toggle.html.twig' ; | |||||
if(!$templateToggle) { | |||||
$template = 'status.html.twig' ; | |||||
} | |||||
$field->setTemplatePath('@LcSov/adminlte/crud/field/'.$template) ; | |||||
return $field ; | |||||
} | } | ||||
} | } |
Subproject commit 0046a14932327424d8cbba5fcea5b9c68db6a5b0 |
{% set item = entity.instance %} | |||||
{% set property_name = field.getProperty() %} | |||||
{% set id_toggle = 'toogle-'~item.id~'-'~property_name %} | |||||
<div class="custom-control custom-switch custom-switch-on-primary custom-switch-off-default" data-propertyname="{{ property_name }}" data-id={{ item.id }}> | |||||
<input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}> | |||||
<label class="custom-control-label" for="{{ id_toggle }}">{{ field.label }}</label> | |||||
</div> |