Browse Source

booleanfield

develop
Charly 3 years ago
parent
commit
09ba687135
6 changed files with 291 additions and 261 deletions
  1. +234
    -235
      Controller/AbstractAdminController.php
  2. +1
    -1
      Controller/Newsletter/NewsletterAdminController.php
  3. +2
    -2
      Field/BooleanField.php
  4. +25
    -0
      Field/ToggleField.php
  5. +5
    -0
      Resources/views/adminlte/crud/field/boolean.html.twig
  6. +24
    -23
      Resources/views/adminlte/crud/index.html.twig

+ 234
- 235
Controller/AbstractAdminController.php View File

public static function getSubscribedServices() public static function getSubscribedServices()
{ {
return array_merge( return array_merge(
parent::getSubscribedServices(),
[
'session' => SessionInterface::class,
'request' => RequestStack::class,
'em' => EntityManagerInterface::class,
'translator_admin' => TranslatorAdmin::class,
'filter_manager' => FilterManager::class,
]
parent::getSubscribedServices(),
[
'session' => SessionInterface::class,
'request' => RequestStack::class,
'em' => EntityManagerInterface::class,
'translator_admin' => TranslatorAdmin::class,
'filter_manager' => FilterManager::class,
]
); );
} }


if ($entity !== null) { if ($entity !== null) {
if ($entity->getParent() !== null) { if ($entity->getParent() !== null) {
$url = $adminUrlGenerator $url = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->set('entityId', $entity->getParent()->getId())
->generateUrl();
->setController($context->getCrud()->getControllerFqcn())
->set('entityId', $entity->getParent()->getId())
->generateUrl();
$action->setLinkUrl($url); $action->setLinkUrl($url);
} }
} else { } else {
$entityId = $context->getRequest()->get('entityId'); $entityId = $context->getRequest()->get('entityId');
if ($entityId != null) { if ($entityId != null) {
$url = $adminUrlGenerator $url = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->setAction($action->getName())
->set('entityId', $entityId)
->generateUrl();
->setController($context->getCrud()->getControllerFqcn())
->setAction($action->getName())
->set('entityId', $entityId)
->generateUrl();
$action->setLinkUrl($url); $action->setLinkUrl($url);
} }
} }
{ {
$entityClass = $this->getEntityFqcn(); $entityClass = $this->getEntityFqcn();
$paramListMaxResults = 'listMaxResults'; $paramListMaxResults = 'listMaxResults';
$paramSessionListMaxResults = $entityClass.'-'.$paramListMaxResults;
$paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
$requestListMaxResults = $this->get('request')->getCurrentRequest()->get($paramListMaxResults); $requestListMaxResults = $this->get('request')->getCurrentRequest()->get($paramListMaxResults);


if ($requestListMaxResults) { if ($requestListMaxResults) {
$this->get('session')->set($paramSessionListMaxResults, $requestListMaxResults); $this->get('session')->set($paramSessionListMaxResults, $requestListMaxResults);
} }
$maxResults = $this->get('session')->get($paramSessionListMaxResults) ? $this->get('session')->get( $maxResults = $this->get('session')->get($paramSessionListMaxResults) ? $this->get('session')->get(
$paramSessionListMaxResults
$paramSessionListMaxResults
) : 30; ) : 30;


$crud->setPaginatorPageSize($maxResults); $crud->setPaginatorPageSize($maxResults);
{ {
if ($this->isInstanceOf(SeoInterface::class)) { if ($this->isInstanceOf(SeoInterface::class)) {
return [ return [
FormField::addPanel('seo')->setTemplateName('crud/field/generic'),
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
'Affiché dans les résultats de recherche Google'
FormField::addPanel('seo')->setTemplateName('crud/field/generic'),
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
'Affiché dans les résultats de recherche Google'
)->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
)->hideOnIndex(), )->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
)->hideOnIndex(),
]; ];
} else { } else {
return null; return null;
{ {
if ($this->isInstanceOf(DevAliasInterface::class)) { if ($this->isInstanceOf(DevAliasInterface::class)) {
return [ return [
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
]; ];
}else{
} else {
return null; return null;
} }

} }


public function sort(AdminContext $context) public function sort(AdminContext $context)


$fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX)); $fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
$filters = $this->get(FilterFactory::class)->create( $filters = $this->get(FilterFactory::class)->create(
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
); );
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters); $queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->get(PaginatorFactory::class)->create($queryBuilder); $paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);
$this->get(EntityFactory::class)->processFieldsForAll($entities, $fields); $this->get(EntityFactory::class)->processFieldsForAll($entities, $fields);


$sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults())) $sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults()))
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
)
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
) )
->getForm();
)
->getForm();


$entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn()); $entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn());
$repository = $entityManager->getRepository($this->getEntityFqcn()); $repository = $entityManager->getRepository($this->getEntityFqcn());
} }


$url = $this->get(AdminUrlGenerator::class) $url = $this->get(AdminUrlGenerator::class)
->setAction(Action::INDEX)
->generateUrl();
->setAction(Action::INDEX)
->generateUrl();
$this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array()); $this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array());


return $this->redirect($url); return $this->redirect($url);
} }


$responseParameters = $this->configureResponseParameters( $responseParameters = $this->configureResponseParameters(
KeyValueStore::new(
[
'pageName' => Crud::PAGE_INDEX,
'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
'entities' => $entities,
'paginator' => $paginator,
'global_actions' => array(),
'batch_actions' => array(),
'filters' => $filters,
'sortable_form' => $sortableForm,
]
)
KeyValueStore::new(
[
'pageName' => Crud::PAGE_INDEX,
'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
'entities' => $entities,
'paginator' => $paginator,
'global_actions' => array(),
'batch_actions' => array(),
'filters' => $filters,
'sortable_form' => $sortableForm,
]
)
); );
$responseParameters->set('fields', $this->configureFields('index')); $responseParameters->set('fields', $this->configureFields('index'));
$event = new AfterCrudActionEvent($context, $responseParameters); $event = new AfterCrudActionEvent($context, $responseParameters);
} }


public function createIndexQueryBuilder( public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder { ): QueryBuilder {
$queryBuilder = parent::createIndexQueryBuilder( $queryBuilder = parent::createIndexQueryBuilder(
$searchDto,
$entityDto,
$fields,
$filters
$searchDto,
$entityDto,
$fields,
$filters
); );


//TOdo utiliser les repositoryQuery ? //TOdo utiliser les repositoryQuery ?
} }


$this->filtersForm = $this->createForm( $this->filtersForm = $this->createForm(
FiltersFormType::class,
null,
array(
'fields' => $fields,
'entity_dto' => $entityDto,
'entity_class' => $this->getEntityFqcn(),
'entity_name' => $entityDto->getName(),
)
FiltersFormType::class,
null,
array(
'fields' => $fields,
'entity_dto' => $entityDto,
'entity_class' => $this->getEntityFqcn(),
'entity_name' => $entityDto->getName(),
)
); );


$filterManager = $this->get('filter_manager'); $filterManager = $this->get('filter_manager');
} }


public function createSortQueryBuilder( public function createSortQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder { ): QueryBuilder {
$queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters); $queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);


$context = $this->get(AdminContextProvider::class)->getContext(); $context = $this->get(AdminContextProvider::class)->getContext();


return $context->getCrudControllers()->findCrudFqcnByEntityFqcn( return $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
$this->get('em')->getEntityName($interface)
$this->get('em')->getEntityName($interface)
); );
} }


public function buildIndexActions(Actions $actions): void public function buildIndexActions(Actions $actions): void
{ {
$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::NEW,
[
'icon' => 'plus',
'label' => $this->get('translator_admin')->transAction('create'),
'add_class' => 'btn-sm',
]
$actions,
Crud::PAGE_INDEX,
Action::NEW,
[
'icon' => 'plus',
'label' => $this->get('translator_admin')->transAction('create'),
'add_class' => 'btn-sm',
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('edit'),
),
]
$actions,
Crud::PAGE_INDEX,
Action::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('edit'),
),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('detail'),
),
]
$actions,
Crud::PAGE_INDEX,
Action::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get('translator_admin')->transAction('detail'),
),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
'label' => $this->get('translator_admin')->transAction('delete'),
]
$actions,
Crud::PAGE_INDEX,
Action::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
'label' => $this->get('translator_admin')->transAction('delete'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->get('translator_admin')->transAction('delete'),
]
$actions,
Crud::PAGE_INDEX,
Action::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->get('translator_admin')->transAction('delete'),
]
); );
} }






$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
); );




$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_continue'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_continue'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->get('translator_admin')->transAction('delete'),
]
$actions,
Crud::PAGE_EDIT,
Action::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->get('translator_admin')->transAction('delete'),
]
); );
} }


$actions->add(Crud::PAGE_NEW, Action::INDEX); $actions->add(Crud::PAGE_NEW, Action::INDEX);


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get('translator_admin')->transAction('save_and_return'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get('translator_admin')->transAction('back_index'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_add_another'),
]
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get('translator_admin')->transAction('save_and_add_another'),
]
); );
} }


{ {
if ($this->isInstanceOf(TranslatableInterface::class)) { if ($this->isInstanceOf(TranslatableInterface::class)) {
$actions->update( $actions->update(
Crud::PAGE_INDEX,
Action::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
Crud::PAGE_INDEX,
Action::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');


return $action;
}
return $action;
}
); );
} }
} }
{ {
if ($this->isInstanceOf(SortableInterface::class)) { if ($this->isInstanceOf(SortableInterface::class)) {
$sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort') $sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort')
->linkToCrudAction('sort')
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();
->linkToCrudAction('sort')
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();


$actions->add(Crud::PAGE_INDEX, $sortAction); $actions->add(Crud::PAGE_INDEX, $sortAction);
} }
{ {
if ($this->isInstanceOf(TreeInterface::class)) { if ($this->isInstanceOf(TreeInterface::class)) {
$indexChildAction = Action::new( $indexChildAction = Action::new(
'index_children',
$this->get('translator_admin')->transAction('index_children'),
'fa fa-list'
'index_children',
$this->get('translator_admin')->transAction('index_children'),
'fa fa-list'
) )
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');


$backParentAction = Action::new( $backParentAction = Action::new(
'index_parent',
$this->get('translator_admin')->transAction('index_parent'),
'fa fa-chevron-left'
'index_parent',
$this->get('translator_admin')->transAction('index_parent'),
'fa fa-chevron-left'
) )
->linkToCrudAction(Action::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();
->linkToCrudAction(Action::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();


$actions->add(Crud::PAGE_INDEX, $backParentAction); $actions->add(Crud::PAGE_INDEX, $backParentAction);
$actions->add(Crud::PAGE_INDEX, $indexChildAction); $actions->add(Crud::PAGE_INDEX, $indexChildAction);
{ {
if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) { if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) {
$actions->update( $actions->update(
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}

if (isset($button['class'])) {
$action->setCssClass($button['class']);
}
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}


if (isset($button['icon'])) {
$action->setIcon('fa fa-'.$button['icon']);
}
if (isset($button['class'])) {
$action->setCssClass($button['class']);
}


if (isset($button['label'])) {
$action->setLabel($button['label']);
}
if (isset($button['icon'])) {
$action->setIcon('fa fa-' . $button['icon']);
}


if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}
if (isset($button['label'])) {
$action->setLabel($button['label']);
}


if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
}
if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}


return $action;
if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
} }

return $action;
}
); );
} }
} }
public function autocompleteFilter(AdminContext $context): JsonResponse public function autocompleteFilter(AdminContext $context): JsonResponse
{ {
$queryBuilder = $this->createIndexQueryBuilder( $queryBuilder = $this->createIndexQueryBuilder(
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
); );
$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT); $autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);


/** @var CrudControllerInterface $controller */ /** @var CrudControllerInterface $controller */
$controller = $this->get(ControllerFactory::class)->getCrudControllerInstance( $controller = $this->get(ControllerFactory::class)->getCrudControllerInstance(
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
Action::INDEX,
$context->getRequest()
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
Action::INDEX,
$context->getRequest()
); );
/** @var FieldDto $field */ /** @var FieldDto $field */
$field = FieldCollection::new( $field = FieldCollection::new(
$controller->configureFields($autocompleteContext['originatingPage'])
$controller->configureFields($autocompleteContext['originatingPage'])
)->getByProperty($autocompleteContext['propertyName']); )->getByProperty($autocompleteContext['propertyName']);


$filterManager = $this->get('filter_manager'); $filterManager = $this->get('filter_manager');
if ($filterManager->isRelationField($field->getProperty())) { if ($filterManager->isRelationField($field->getProperty())) {
$queryBuilder->select($autocompleteContext['propertyName']); $queryBuilder->select($autocompleteContext['propertyName']);
} else { } else {
$queryBuilder->select('entity.'.$autocompleteContext['propertyName']);
$queryBuilder->select('entity.' . $autocompleteContext['propertyName']);
} }


$responses = array(); $responses = array();

+ 1
- 1
Controller/Newsletter/NewsletterAdminController.php View File

use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController; use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Newsletter\NewsletterFactory; use Lc\SovBundle\Factory\Newsletter\NewsletterFactory;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\ToggleField;
use Lc\SovBundle\Field\CKEditorField; use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;



+ 2
- 2
Field/BooleanField.php View File

return (new self()) return (new self())
->setProperty($propertyName) ->setProperty($propertyName)
->setLabel($label) ->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/toggle.html.twig')
->setFormType(CheckboxType::class);
->setTemplatePath('@LcSov/adminlte/crud/field/boolean.html.twig')
->setFormType(TextType::class);
} }


} }

+ 25
- 0
Field/ToggleField.php View File

<?php

namespace Lc\SovBundle\Field;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

/**
* @author La clic ! <contact@laclic.fr>
*/
final class ToggleField 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(CheckboxType::class);
}

}

+ 5
- 0
Resources/views/adminlte/crud/field/boolean.html.twig View File

{% if field.value %}
<span class="badge badge-success">Oui</span>
{% else %}
<span class="badge badge-danger">Non</span>
{% endif %}

+ 24
- 23
Resources/views/adminlte/crud/index.html.twig View File



{% block entity_actions %} {% block entity_actions %}
<td class="actions text-right"> <td class="actions text-right">
{% set in_dropdown_class = 'in-dropdown' %}
{% for action in entity.actions %}
{% if not (in_dropdown_class in action.cssClass) %}
{{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: 0 }, with_context = false) }}
{% endif %}
{% endfor %}

<div class="dropdown dropdown-actions">
<a class="dropdown-toggle btn btn-secondary btn-sm" href="#"
role="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
</a>

<div class="dropdown-menu dropdown-menu-right">
{% for action in entity.actions %}
{% if in_dropdown_class in action.cssClass %}
{{ include(action.templatePath, { action: action, isIncludedInDropdown: 1 }, with_context = false) }}
{% endif %}
{% endfor %}
{% if entity.actions.count > 0 %}
{% set in_dropdown_class = 'in-dropdown' %}
{% for action in entity.actions %}
{% if not (in_dropdown_class in action.cssClass) %}
{{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: 0 }, with_context = false) }}
{% endif %}
{% endfor %}
<div class="dropdown dropdown-actions">
<a class="dropdown-toggle btn btn-secondary btn-sm" href="#"
role="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
</a>

<div class="dropdown-menu dropdown-menu-right">
{% for action in entity.actions %}
{% if in_dropdown_class in action.cssClass %}
{{ include(action.templatePath, { action: action, isIncludedInDropdown: 1 }, with_context = false) }}
{% endif %}
{% endfor %}
</div>
</div> </div>
</div>
{% endif %}


{% if not ea.crud.showEntityActionsAsDropdown %} {% if not ea.crud.showEntityActionsAsDropdown %}


{% if filters_form is defined %} {% if filters_form is defined %}
{{ form_start(filters_form, {'attr' :{'id' : 'filters-form'}}) }} {{ form_start(filters_form, {'attr' :{'id' : 'filters-form'}}) }}


{#<input type="hidden" name="entity" value="{{ _entity_config.name }}">
{# <input type="hidden" name="entity" value="{{ _entity_config.name }}">
<input type="hidden" name="menuIndex" value="{{ app.request.get('menuIndex') }}"> <input type="hidden" name="menuIndex" value="{{ app.request.get('menuIndex') }}">
<input type="hidden" name="submenuIndex" value="{{ app.request.get('submenuIndex') }}"> <input type="hidden" name="submenuIndex" value="{{ app.request.get('submenuIndex') }}">
<input type="hidden" name="sortField" value="{{ app.request.get('sortField', '') }}"> <input type="hidden" name="sortField" value="{{ app.request.get('sortField', '') }}">
<input type="hidden" name="sortDirection" <input type="hidden" name="sortDirection"
value="{{ app.request.get('sortDirection', 'DESC') }}"> value="{{ app.request.get('sortDirection', 'DESC') }}">
<input type="hidden" name="action" value="{{ app.request.get('action') }}">#}
<input type="hidden" name="action" value="{{ app.request.get('action') }}"> #}
{{ form_end(filters_form) }} {{ form_end(filters_form) }}
{% endif %} {% endif %}
{% endblock filters_form %} {% endblock filters_form %}
}); });
});*/ });*/


/* {% if filters|length > 0 %}
/* {% if filters|length > 0 %}
const filterModal = document.querySelector('#modal-filters'); const filterModal = document.querySelector('#modal-filters');


const removeFilter = function (field) { const removeFilter = function (field) {

Loading…
Cancel
Save