|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection; |
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; |
|
|
|
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; |
|
|
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; |
|
|
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; |
|
|
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; |
|
|
use Lc\SovBundle\Doctrine\Extension\SeoInterface; |
|
|
use Lc\SovBundle\Doctrine\Extension\SeoInterface; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
public static function getSubscribedServices() |
|
|
public static function getSubscribedServices() |
|
|
{ |
|
|
{ |
|
|
return array_merge(parent::getSubscribedServices(), [ |
|
|
|
|
|
'session' => SessionInterface::class, |
|
|
|
|
|
'request' => RequestStack::class, |
|
|
|
|
|
'em' => EntityManagerInterface::class, |
|
|
|
|
|
'translator_admin' => TranslatorAdmin::class, |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
return array_merge( |
|
|
|
|
|
parent::getSubscribedServices(), |
|
|
|
|
|
[ |
|
|
|
|
|
'session' => SessionInterface::class, |
|
|
|
|
|
'request' => RequestStack::class, |
|
|
|
|
|
'em' => EntityManagerInterface::class, |
|
|
|
|
|
'translator_admin' => TranslatorAdmin::class, |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function configureActions(Actions $actions): Actions |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
/* Translatable */ |
|
|
|
|
|
if ($this->isInstanceOf(TranslatableInterface::class)) { |
|
|
|
|
|
$actions->update( |
|
|
|
|
|
Crud::PAGE_INDEX, |
|
|
|
|
|
Action::EDIT, |
|
|
|
|
|
function (Action $action) { |
|
|
|
|
|
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig'); |
|
|
|
|
|
|
|
|
|
|
|
return $action; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Boutons des actions dans les listes */ |
|
|
|
|
|
$actionsArray[Crud::PAGE_INDEX] = [ |
|
|
|
|
|
Action::NEW => [ |
|
|
|
|
|
'icon' => 'plus', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('create'), |
|
|
|
|
|
'add_class' => 'btn-sm' |
|
|
|
|
|
], |
|
|
|
|
|
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') |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
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') |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
Action::DELETE => [ |
|
|
|
|
|
'icon' => 'trash', |
|
|
|
|
|
'dropdown' => true, |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('delete') |
|
|
|
|
|
], |
|
|
|
|
|
Action::BATCH_DELETE => [ |
|
|
|
|
|
'class' => 'btn btn-sm btn-danger', |
|
|
|
|
|
'icon' => 'trash', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('delete') |
|
|
|
|
|
], |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
/* Boutons des actions dans l'édition */ |
|
|
|
|
|
$actionSaveAndReturn = [ |
|
|
|
|
|
'add_class' => 'float-right', |
|
|
|
|
|
'icon' => 'check', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('save_and_return') |
|
|
|
|
|
]; |
|
|
|
|
|
$actionIndex = [ |
|
|
|
|
|
'icon' => 'chevron-left', |
|
|
|
|
|
'class' => 'btn btn-link', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('back_index') |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$actionsArray[Crud::PAGE_EDIT] = [ |
|
|
|
|
|
Action::SAVE_AND_CONTINUE => [ |
|
|
|
|
|
'class' => 'btn btn-info float-right', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('save_and_continue') |
|
|
|
|
|
], |
|
|
|
|
|
Action::DELETE => [ |
|
|
|
|
|
'icon' => 'trash', |
|
|
|
|
|
'class' => 'btn btn-outline-danger action-delete', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('delete') |
|
|
|
|
|
], |
|
|
|
|
|
Action::SAVE_AND_RETURN => $actionSaveAndReturn, |
|
|
|
|
|
Action::INDEX => $actionIndex, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$actionsArray[Crud::PAGE_NEW] = [ |
|
|
|
|
|
Action::SAVE_AND_ADD_ANOTHER => [ |
|
|
|
|
|
'class' => 'btn btn-info float-right', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('save_and_add_another') |
|
|
|
|
|
], |
|
|
|
|
|
Action::SAVE_AND_RETURN => $actionSaveAndReturn, |
|
|
|
|
|
Action::INDEX => $actionIndex, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$actions->add(Crud::PAGE_EDIT, Action::INDEX); |
|
|
|
|
|
$actions->add(Crud::PAGE_EDIT, Action::DELETE); |
|
|
|
|
|
$actions->add(Crud::PAGE_NEW, Action::INDEX); |
|
|
|
|
|
|
|
|
|
|
|
if ($this->isInstanceOf(SortableInterface::class)) { |
|
|
|
|
|
$sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort') |
|
|
|
|
|
->linkToCrudAction('sort') |
|
|
|
|
|
->setCssClass('btn btn-sm btn-success') |
|
|
|
|
|
->createAsGlobalAction(); |
|
|
|
|
|
|
|
|
|
|
|
$actions->add(Crud::PAGE_INDEX, $sortAction); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->isInstanceOf(TreeInterface::class)) { |
|
|
|
|
|
$indexChildAction = Action::new( |
|
|
|
|
|
'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'); |
|
|
|
|
|
|
|
|
|
|
|
$backParentAction = Action::new( |
|
|
|
|
|
'index_parent', |
|
|
|
|
|
$this->get('translator_admin')->transAction('index_parent'), |
|
|
|
|
|
'fa fa-chevron-left' |
|
|
|
|
|
) |
|
|
|
|
|
->linkToCrudAction(Action::INDEX) |
|
|
|
|
|
->setCssClass('btn btn-sm btn-info') |
|
|
|
|
|
->createAsGlobalAction(); |
|
|
|
|
|
|
|
|
|
|
|
$actions->add(Crud::PAGE_INDEX, $backParentAction); |
|
|
|
|
|
$actions->add(Crud::PAGE_INDEX, $indexChildAction); |
|
|
|
|
|
|
|
|
public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore |
|
|
|
|
|
{ |
|
|
|
|
|
$this->overrideGlobalActions($responseParameters->get('global_actions')); |
|
|
|
|
|
$this->overrideEntitiesActions($responseParameters->get('entities')); |
|
|
|
|
|
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { |
|
|
|
|
|
$responseParameters->set('fields', $this->configureFields('index')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$actions->reorder(Crud::PAGE_EDIT, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_CONTINUE]); |
|
|
|
|
|
$actions->reorder(Crud::PAGE_NEW, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_ADD_ANOTHER]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($actionsArray as $crudActionName => $actionsStyle) { |
|
|
|
|
|
foreach ($actionsStyle as $actionName => $button) { |
|
|
|
|
|
// si l'action existe |
|
|
|
|
|
if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) { |
|
|
|
|
|
$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']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['icon'])) { |
|
|
|
|
|
$action->setIcon('fa fa-' . $button['icon']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['label'])) { |
|
|
|
|
|
$action->setLabel($button['label']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['dropdown']) && $button['dropdown']) { |
|
|
|
|
|
$action->addCssClass('in-dropdown'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $responseParameters; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (isset($button['html_attributes']) && $button['html_attributes']) { |
|
|
|
|
|
$action->setHtmlAttributes($button['html_attributes']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function overrideEntitiesActions(?EntityCollection $entities): void |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $action; |
|
|
|
|
|
|
|
|
public function overrideGlobalActions(?ActionCollection $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
if ($actions) { |
|
|
|
|
|
$context = $this->get(AdminContextProvider::class)->getContext(); |
|
|
|
|
|
$adminUrlGenerator = $this->get(AdminUrlGenerator::class); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($actions as $i => $action) { |
|
|
|
|
|
//récriture du bouton 'retour au parent' |
|
|
|
|
|
if ($action->getName() == 'index_parent') { |
|
|
|
|
|
$entity = $context->getEntity()->getInstance(); |
|
|
|
|
|
if ($entity !== null) { |
|
|
|
|
|
if ($entity->getParent() !== null) { |
|
|
|
|
|
$url = $adminUrlGenerator |
|
|
|
|
|
->setController($context->getCrud()->getControllerFqcn()) |
|
|
|
|
|
->set('entityId', $entity->getParent()->getId()) |
|
|
|
|
|
->generateUrl(); |
|
|
|
|
|
$action->setLinkUrl($url); |
|
|
} |
|
|
} |
|
|
); |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
unset($actions[$i]); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $actions; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore |
|
|
|
|
|
{ |
|
|
|
|
|
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { |
|
|
|
|
|
$responseParameters->set('fields', $this->configureFields('index')); |
|
|
|
|
|
|
|
|
if ($action->getName() == 'sort') { |
|
|
|
|
|
$entityId = $context->getRequest()->get('entityId'); |
|
|
|
|
|
if ($entityId != null) { |
|
|
|
|
|
$url = $adminUrlGenerator |
|
|
|
|
|
->setController($context->getCrud()->getControllerFqcn()) |
|
|
|
|
|
->setAction($action->getName()) |
|
|
|
|
|
->set('entityId', $entityId) |
|
|
|
|
|
->generateUrl(); |
|
|
|
|
|
$action->setLinkUrl($url); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $responseParameters; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function configureCrud(Crud $crud): Crud |
|
|
public function configureCrud(Crud $crud): Crud |
|
|
|
|
|
|
|
|
$crud = parent::configureCrud($crud); |
|
|
$crud = parent::configureCrud($crud); |
|
|
|
|
|
|
|
|
$this->setMaxResults($crud); |
|
|
$this->setMaxResults($crud); |
|
|
|
|
|
|
|
|
if ($this->isInstanceOf(SortableInterface::class)) { |
|
|
if ($this->isInstanceOf(SortableInterface::class)) { |
|
|
$crud->setDefaultSort(['position' => 'ASC']); |
|
|
$crud->setDefaultSort(['position' => 'ASC']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $crud; |
|
|
return $crud; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function setMaxResults(Crud $crud) |
|
|
|
|
|
|
|
|
public function setMaxResults(Crud $crud): void |
|
|
{ |
|
|
{ |
|
|
$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)) { |
|
|
$seoPanel = [ |
|
|
$seoPanel = [ |
|
|
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' |
|
|
|
|
|
|
|
|
FormField::addPanel('seo')->setTemplateName('crud/field/generic'), |
|
|
|
|
|
TextField::new('metaTitle')->setLabel('Meta Title')->setHelp( |
|
|
|
|
|
'Affiché dans les résultats de recherche Google' |
|
|
)->hideOnIndex(), |
|
|
)->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(), |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($this->isInstanceOf(DevAliasInterface::class)) { |
|
|
if ($this->isInstanceOf(DevAliasInterface::class)) { |
|
|
$confPanel = [ |
|
|
$confPanel = [ |
|
|
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'), |
|
|
|
|
|
TextField::new('devAlias')->hideOnIndex(), |
|
|
|
|
|
|
|
|
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'), |
|
|
|
|
|
TextField::new('devAlias')->hideOnIndex(), |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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 ? |
|
|
if ($this->isInstanceOf(TreeInterface::class)) { |
|
|
if ($this->isInstanceOf(TreeInterface::class)) { |
|
|
$entityId = $searchDto->getRequest()->get('entityId'); |
|
|
$entityId = $searchDto->getRequest()->get('entityId'); |
|
|
if ($entityId !== null) { |
|
|
if ($entityId !== null) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return in_array($interfaceName, class_implements($this->getEntityFqcn())); |
|
|
return in_array($interfaceName, class_implements($this->getEntityFqcn())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getControllerFqcnByInterface(string $interface): string |
|
|
|
|
|
{ |
|
|
|
|
|
$context = $this->get(AdminContextProvider::class)->getContext(); |
|
|
|
|
|
|
|
|
|
|
|
return $context->getCrudControllers()->findCrudFqcnByEntityFqcn( |
|
|
|
|
|
$this->get('em')->getEntityName($interface) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void |
|
|
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
$entityManager->flush(); |
|
|
$entityManager->flush(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function configureActions(Actions $actions): Actions |
|
|
|
|
|
{ |
|
|
|
|
|
$this->buildIndexActions($actions); |
|
|
|
|
|
$this->buildEditActions($actions); |
|
|
|
|
|
$this->buildDetailActions($actions); |
|
|
|
|
|
$this->buildNewActions($actions); |
|
|
|
|
|
$this->handleTranslatableEntityActions($actions); |
|
|
|
|
|
$this->handleSortableEntityActions($actions); |
|
|
|
|
|
$this->handleTreeEntityActions($actions); |
|
|
|
|
|
|
|
|
|
|
|
/*$actions->reorder(Crud::PAGE_EDIT, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_CONTINUE, Action::DELETE]); |
|
|
|
|
|
$actions->reorder(Crud::PAGE_NEW, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_ADD_ANOTHER]);*/ |
|
|
|
|
|
|
|
|
|
|
|
return $actions; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function buildIndexActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
$this->actionUpdate( |
|
|
|
|
|
$actions, |
|
|
|
|
|
Crud::PAGE_INDEX, |
|
|
|
|
|
Action::NEW, |
|
|
|
|
|
[ |
|
|
|
|
|
'icon' => 'plus', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('create'), |
|
|
|
|
|
'add_class' => 'btn-sm', |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$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'), |
|
|
|
|
|
), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$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'), |
|
|
|
|
|
), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$this->actionUpdate( |
|
|
|
|
|
$actions, |
|
|
|
|
|
Crud::PAGE_INDEX, |
|
|
|
|
|
Action::DELETE, |
|
|
|
|
|
[ |
|
|
|
|
|
'icon' => 'trash', |
|
|
|
|
|
'dropdown' => true, |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('delete'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$this->actionUpdate( |
|
|
|
|
|
$actions, |
|
|
|
|
|
Crud::PAGE_INDEX, |
|
|
|
|
|
Action::BATCH_DELETE, |
|
|
|
|
|
[ |
|
|
|
|
|
'class' => 'btn btn-sm btn-danger', |
|
|
|
|
|
'icon' => 'trash', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('delete'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function buildEditActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
$actions->add(Crud::PAGE_EDIT, Action::INDEX); |
|
|
|
|
|
$actions->add(Crud::PAGE_EDIT, Action::DELETE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$this->actionUpdate( |
|
|
|
|
|
$actions, |
|
|
|
|
|
Crud::PAGE_EDIT, |
|
|
|
|
|
Action::INDEX, |
|
|
|
|
|
[ |
|
|
|
|
|
'icon' => 'chevron-left', |
|
|
|
|
|
'class' => 'btn btn-link', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('back_index'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$this->actionUpdate( |
|
|
|
|
|
$actions, |
|
|
|
|
|
Crud::PAGE_EDIT, |
|
|
|
|
|
Action::DELETE, |
|
|
|
|
|
[ |
|
|
|
|
|
'icon' => 'trash', |
|
|
|
|
|
'class' => 'btn btn-outline-danger action-delete', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('delete'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function buildDetailActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function buildNewActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
$actions->add(Crud::PAGE_NEW, Action::INDEX); |
|
|
|
|
|
|
|
|
|
|
|
$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'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$this->actionUpdate( |
|
|
|
|
|
$actions, |
|
|
|
|
|
Crud::PAGE_EDIT, |
|
|
|
|
|
Action::INDEX, |
|
|
|
|
|
[ |
|
|
|
|
|
'icon' => 'chevron-left', |
|
|
|
|
|
'class' => 'btn btn-link', |
|
|
|
|
|
'label' => $this->get('translator_admin')->transAction('back_index'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$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'), |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function handleTranslatableEntityActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
if ($this->isInstanceOf(TranslatableInterface::class)) { |
|
|
|
|
|
$actions->update( |
|
|
|
|
|
Crud::PAGE_INDEX, |
|
|
|
|
|
Action::EDIT, |
|
|
|
|
|
function (Action $action) { |
|
|
|
|
|
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig'); |
|
|
|
|
|
|
|
|
|
|
|
return $action; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function handleSortableEntityActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
if ($this->isInstanceOf(SortableInterface::class)) { |
|
|
|
|
|
$sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort') |
|
|
|
|
|
->linkToCrudAction('sort') |
|
|
|
|
|
->setCssClass('btn btn-sm btn-success') |
|
|
|
|
|
->createAsGlobalAction(); |
|
|
|
|
|
|
|
|
|
|
|
$actions->add(Crud::PAGE_INDEX, $sortAction); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function handleTreeEntityActions(Actions $actions): void |
|
|
|
|
|
{ |
|
|
|
|
|
if ($this->isInstanceOf(TreeInterface::class)) { |
|
|
|
|
|
$indexChildAction = Action::new( |
|
|
|
|
|
'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'); |
|
|
|
|
|
|
|
|
|
|
|
$backParentAction = Action::new( |
|
|
|
|
|
'index_parent', |
|
|
|
|
|
$this->get('translator_admin')->transAction('index_parent'), |
|
|
|
|
|
'fa fa-chevron-left' |
|
|
|
|
|
) |
|
|
|
|
|
->linkToCrudAction(Action::INDEX) |
|
|
|
|
|
->setCssClass('btn btn-sm btn-info') |
|
|
|
|
|
->createAsGlobalAction(); |
|
|
|
|
|
|
|
|
|
|
|
$actions->add(Crud::PAGE_INDEX, $backParentAction); |
|
|
|
|
|
$actions->add(Crud::PAGE_INDEX, $indexChildAction); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function actionUpdate($actions, $crudActionName, $actionName, array $button): void |
|
|
|
|
|
{ |
|
|
|
|
|
if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) { |
|
|
|
|
|
$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']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['icon'])) { |
|
|
|
|
|
$action->setIcon('fa fa-'.$button['icon']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['label'])) { |
|
|
|
|
|
$action->setLabel($button['label']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['dropdown']) && $button['dropdown']) { |
|
|
|
|
|
$action->addCssClass('in-dropdown'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($button['html_attributes']) && $button['html_attributes']) { |
|
|
|
|
|
$action->setHtmlAttributes($button['html_attributes']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $action; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|