瀏覽代碼

Adminlte : status field

tags/0.1
Guillaume 3 年之前
父節點
當前提交
f13f308763
共有 4 個文件被更改,包括 50 次插入4 次删除
  1. +30
    -0
      Field/BooleanField.php
  2. +11
    -3
      Field/StatusField.php
  3. +0
    -1
      Resources/assets/tabler
  4. +9
    -0
      Resources/views/adminlte/crud/field/toggle.html.twig

+ 30
- 0
Field/BooleanField.php 查看文件

@@ -0,0 +1,30 @@
<?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]);
}

}

+ 11
- 3
Field/StatusField.php 查看文件

@@ -15,16 +15,24 @@ final class StatusField implements FieldInterface
{
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)
->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/status.html.twig')
->setFormType(ChoiceType::class)
->setFormTypeOption('expanded', false)
->setFormTypeOption('multiple', false)
->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 ;
}

}

+ 0
- 1
Resources/assets/tabler

@@ -1 +0,0 @@
Subproject commit 0046a14932327424d8cbba5fcea5b9c68db6a5b0

+ 9
- 0
Resources/views/adminlte/crud/field/toggle.html.twig 查看文件

@@ -0,0 +1,9 @@

{% 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>

Loading…
取消
儲存