use Lc\SovBundle\Field\CollectionField; | use Lc\SovBundle\Field\CollectionField; | ||||
use Lc\SovBundle\Field\GalleryManagerField; | use Lc\SovBundle\Field\GalleryManagerField; | ||||
use Lc\SovBundle\Form\Type\Crud\PositionType; | use Lc\SovBundle\Form\Type\Crud\PositionType; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||||
use Symfony\Component\Form\Extension\Core\Type\TextType; | use Symfony\Component\Form\Extension\Core\Type\TextType; | ||||
{ | { | ||||
protected $session; | protected $session; | ||||
protected $request; | protected $request; | ||||
public function __construct(SessionInterface $session, RequestStack $request, EntityManager $em, Environment $twig) | |||||
{ | |||||
protected $translatorAdmin; | |||||
public function __construct( | |||||
SessionInterface $session, | |||||
RequestStack $request, | |||||
EntityManager $em, | |||||
Environment $twig, | |||||
TranslatorAdmin $translatorAdmin | |||||
) { | |||||
$this->session = $session; | $this->session = $session; | ||||
$this->request = $request; | $this->request = $request; | ||||
$this->em = $em; | $this->em = $em; | ||||
$this->twig = $twig; | $this->twig = $twig; | ||||
$this->translatorAdmin = $translatorAdmin; | |||||
} | } | ||||
public function configureActions(Actions $actions): Actions | public function configureActions(Actions $actions): Actions | ||||
$actionsArray[Crud::PAGE_INDEX] = [ | $actionsArray[Crud::PAGE_INDEX] = [ | ||||
Action::NEW => [ | Action::NEW => [ | ||||
'icon' => 'plus', | 'icon' => 'plus', | ||||
'label' => 'Créer', | |||||
'label' => $this->translatorAdmin->transAction('create'), | |||||
'add_class' => 'btn-sm' | 'add_class' => 'btn-sm' | ||||
], | ], | ||||
Action::EDIT => [ | Action::EDIT => [ | ||||
'class' => 'btn btn-sm btn-primary', | 'class' => 'btn btn-sm btn-primary', | ||||
'icon' => 'edit', | 'icon' => 'edit', | ||||
'label' => false, | 'label' => false, | ||||
'html_attributes' => array('data-toggle' => 'tooltip', 'title' => 'Éditer') | |||||
'html_attributes' => array( | |||||
'data-toggle' => 'tooltip', | |||||
'title' => $this->translatorAdmin->transAction('edit') | |||||
) | |||||
], | ], | ||||
Action::DELETE => [ | Action::DELETE => [ | ||||
'icon' => 'trash', | 'icon' => 'trash', | ||||
'dropdown' => true, | 'dropdown' => true, | ||||
'label' => $this->translatorAdmin->transAction('delete') | |||||
], | ], | ||||
Action::BATCH_DELETE => [ | Action::BATCH_DELETE => [ | ||||
'class' => 'btn btn-sm btn-danger', | 'class' => 'btn btn-sm btn-danger', | ||||
'icon' => 'trash', | 'icon' => 'trash', | ||||
'label' => $this->translatorAdmin->transAction('delete') | |||||
], | ], | ||||
]; | ]; | ||||
$actionSaveAndReturn = [ | $actionSaveAndReturn = [ | ||||
'add_class' => 'float-right', | 'add_class' => 'float-right', | ||||
'icon' => 'check', | 'icon' => 'check', | ||||
'label' => $this->translatorAdmin->transAction('save_and_return') | |||||
]; | ]; | ||||
$actionIndex = [ | $actionIndex = [ | ||||
'icon' => 'chevron-left', | 'icon' => 'chevron-left', | ||||
'class' => 'btn btn-link', | 'class' => 'btn btn-link', | ||||
'label' => $this->translatorAdmin->transAction('back_index') | |||||
]; | ]; | ||||
$actionsArray[Crud::PAGE_EDIT] = [ | $actionsArray[Crud::PAGE_EDIT] = [ | ||||
Action::SAVE_AND_CONTINUE => [ | Action::SAVE_AND_CONTINUE => [ | ||||
'class' => 'btn btn-info float-right', | 'class' => 'btn btn-info float-right', | ||||
'label' => $this->translatorAdmin->transAction('save_and_continue') | |||||
], | ], | ||||
Action::DELETE => [ | Action::DELETE => [ | ||||
'icon' => 'trash', | 'icon' => 'trash', | ||||
'class' => 'btn btn-outline-danger action-delete', | 'class' => 'btn btn-outline-danger action-delete', | ||||
'label' => $this->translatorAdmin->transAction('delete') | |||||
], | ], | ||||
Action::SAVE_AND_RETURN => $actionSaveAndReturn, | Action::SAVE_AND_RETURN => $actionSaveAndReturn, | ||||
Action::INDEX => $actionIndex, | Action::INDEX => $actionIndex, | ||||
$actionsArray[Crud::PAGE_NEW] = [ | $actionsArray[Crud::PAGE_NEW] = [ | ||||
Action::SAVE_AND_ADD_ANOTHER => [ | Action::SAVE_AND_ADD_ANOTHER => [ | ||||
'class' => 'btn btn-info float-right', | 'class' => 'btn btn-info float-right', | ||||
'label' => $this->translatorAdmin->transAction('save_and_add_another') | |||||
], | ], | ||||
Action::SAVE_AND_RETURN => $actionSaveAndReturn, | Action::SAVE_AND_RETURN => $actionSaveAndReturn, | ||||
Action::INDEX => $actionIndex, | Action::INDEX => $actionIndex, | ||||
$actions->add(Crud::PAGE_NEW, Action::INDEX); | $actions->add(Crud::PAGE_NEW, Action::INDEX); | ||||
if ($this->isInstanceOf(SortableInterface::class)) { | if ($this->isInstanceOf(SortableInterface::class)) { | ||||
$sortAction = Action::new('sort', 'Ordonner', 'fa fa-sort') | |||||
$sortAction = Action::new('sort', $this->translatorAdmin->transAction('sort'), 'fa fa-sort') | |||||
->linkToCrudAction('sort') | ->linkToCrudAction('sort') | ||||
->setCssClass('btn btn-sm btn-success') | ->setCssClass('btn btn-sm btn-success') | ||||
->createAsGlobalAction(); | ->createAsGlobalAction(); | ||||
if ($this->isInstanceOf(TreeInterface::class)) { | if ($this->isInstanceOf(TreeInterface::class)) { | ||||
$indexChildAction = Action::new('index_children', 'Afficher les enfants', 'fa fa-list') | |||||
$indexChildAction = Action::new( | |||||
'index_children', | |||||
$this->translatorAdmin->transAction('index_children'), | |||||
'fa fa-list' | |||||
) | |||||
->linkToCrudAction(Action::INDEX) | ->linkToCrudAction(Action::INDEX) | ||||
->setLabel('') | ->setLabel('') | ||||
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants')) | ->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants')) | ||||
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig') | ->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig') | ||||
->setCssClass('btn btn-sm btn-success'); | ->setCssClass('btn btn-sm btn-success'); | ||||
$backParentAction = Action::new('index_parent', 'Retour au parent', 'fa fa-chevron-left') | |||||
$backParentAction = Action::new( | |||||
'index_parent', | |||||
$this->translatorAdmin->transAction('index_parent'), | |||||
'fa fa-chevron-left' | |||||
) | |||||
->linkToCrudAction(Action::INDEX) | ->linkToCrudAction(Action::INDEX) | ||||
->setCssClass('btn btn-sm btn-info') | ->setCssClass('btn btn-sm btn-info') | ||||
->createAsGlobalAction(); | ->createAsGlobalAction(); | ||||
if ($this->isInstanceOf(SortableInterface::class)) { | if ($this->isInstanceOf(SortableInterface::class)) { | ||||
$seoPanel = [ | $seoPanel = [ | ||||
FormField::addPanel('seo'), | FormField::addPanel('seo'), | ||||
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(), | |||||
TextField::new('metaTitle')->hideOnIndex(), | |||||
TextareaField::new('metaDescription')->hideOnIndex(), | |||||
CollectionField::new('oldUrls') | CollectionField::new('oldUrls') | ||||
->setFormTypeOption('entry_type', TextType::class)->setLabel( | ->setFormTypeOption('entry_type', TextType::class)->setLabel( | ||||
'Anciennes urls du document' | 'Anciennes urls du document' | ||||
$url = $this->get(AdminUrlGenerator::class) | $url = $this->get(AdminUrlGenerator::class) | ||||
->setAction(Action::INDEX) | ->setAction(Action::INDEX) | ||||
->generateUrl(); | ->generateUrl(); | ||||
$this->addFlash('success', 'Position modifié', array()); | |||||
$this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array()); | |||||
return $this->redirect($url); | return $this->redirect($url); | ||||
} | } | ||||
public function edit(AdminContext $context) | public function edit(AdminContext $context) | ||||
{ | { | ||||
$response = parent::edit($context); ; | |||||
$response = parent::edit($context);; | |||||
// on vide le flash bag si édition en ajax (notification déjà affichée en Javascript) | // on vide le flash bag si édition en ajax (notification déjà affichée en Javascript) | ||||
if ($context->getRequest()->isXmlHttpRequest()) { | if ($context->getRequest()->isXmlHttpRequest()) { | ||||
$this->session->getFlashBag()->clear() ; | |||||
$this->session->getFlashBag()->clear(); | |||||
} | } | ||||
return $response ; | |||||
return $response; | |||||
} | } | ||||
public function isInstanceOf(string $interfaceName): bool | public function isInstanceOf(string $interfaceName): bool |
use Lc\SovBundle\Doctrine\EntityManager; | use Lc\SovBundle\Doctrine\EntityManager; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||||
use Symfony\Component\Form\AbstractType; | use Symfony\Component\Form\AbstractType; | ||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType; | use Symfony\Component\Form\Extension\Core\Type\PasswordType; | ||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType; | use Symfony\Component\Form\Extension\Core\Type\RepeatedType; | ||||
class ChangePasswordFormType extends AbstractType | class ChangePasswordFormType extends AbstractType | ||||
{ | { | ||||
protected $em ; | |||||
protected $em; | |||||
protected $translatorAdmin; | |||||
public function __construct(EntityManager $em) | |||||
public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin) | |||||
{ | { | ||||
$this->em = $em ; | |||||
$this->em = $em; | |||||
$this->translatorAdmin = $translatorAdmin; | |||||
} | } | ||||
/** | /** | ||||
'submit', | 'submit', | ||||
SubmitType::class, | SubmitType::class, | ||||
array( | array( | ||||
'label' => new TranslatableMessage('action.save', [], 'admin') | |||||
'label' => $this->translatorAdmin->transAction('save') | |||||
) | ) | ||||
); | ); | ||||
} | } |
use Lc\SovBundle\Doctrine\EntityManager; | use Lc\SovBundle\Doctrine\EntityManager; | ||||
use Lc\SovBundle\Model\File\FileInterface; | use Lc\SovBundle\Model\File\FileInterface; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||||
use Symfony\Component\Form\AbstractType; | use Symfony\Component\Form\AbstractType; | ||||
use Symfony\Component\Form\Extension\Core\Type\EmailType; | use Symfony\Component\Form\Extension\Core\Type\EmailType; | ||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
class ProfileFormType extends AbstractType | class ProfileFormType extends AbstractType | ||||
{ | { | ||||
protected $em; | protected $em; | ||||
protected $translatorAdmin; | |||||
public function __construct(EntityManager $em) | |||||
public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin) | |||||
{ | { | ||||
$this->em = $em; | $this->em = $em; | ||||
$this->translatorAdmin = $translatorAdmin; | |||||
} | } | ||||
public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
'submit', | 'submit', | ||||
SubmitType::class, | SubmitType::class, | ||||
[ | [ | ||||
'label' => new TranslatableMessage('action.save', [], 'admin') | |||||
'label' => $this->translatorAdmin->transAction('save') | |||||
] | ] | ||||
); | ); | ||||
} | } |
flash_message: | |||||
create: Le contenu "%name%" a été créé avec succès. | |||||
update: Le contenu "%name%" a été mis à jour avec succès. | |||||
delete: Le contenu "%name%" a été supprimé avec succès. | |||||
menu: | menu: | ||||
dashboard: Tableau de bord | dashboard: Tableau de bord | ||||
page: Pages | page: Pages | ||||
user: | |||||
label: Utilisateurs | |||||
childs: | |||||
index: Liste | |||||
account: | |||||
label: Mon compte | |||||
childs: | |||||
profile: Informations personnelles | |||||
password: Mot de passe | |||||
user: Utilisateurs | |||||
user_index: Liste | |||||
account: Mon compte | |||||
account_profile: Informations personnelles | |||||
account_password: Mot de passe | |||||
title: | title: | ||||
dashboard: Tableau de bord | dashboard: Tableau de bord | ||||
profile: Mes informations personnelles | profile: Mes informations personnelles | ||||
change_password: Changer de mot de passe | change_password: Changer de mot de passe | ||||
action: | |||||
create: Créer | |||||
edit: Éditer | |||||
save: Sauvegarder | |||||
sort: Ordonner | |||||
delete: Supprimer | |||||
index_children: Afficher les enfants | |||||
index_parent: Retour au parent | |||||
back_index: Retour à la liste | |||||
save_and_return: Sauvegarder les modifications | |||||
save_and_continue: Sauvegarder et continuer l'édition | |||||
save_and_add_another: Créer et ajouter un nouvel élément | |||||
flash_message: | |||||
create: Le contenu "%name%" a été créé avec succès. | |||||
update: Le contenu "%name%" a été mis à jour avec succès. | |||||
delete: Le contenu "%name%" a été supprimé avec succès. | |||||
sort: Position modifiée | |||||
entity: | entity: | ||||
user: | |||||
User: | |||||
label: Utilisateur | label: Utilisateur | ||||
label_plurial: Utilisateurs | label_plurial: Utilisateurs | ||||
fields: | fields: | ||||
firstname: Prénom | firstname: Prénom | ||||
lastname: Nom | lastname: Nom | ||||
page: | |||||
Page: | |||||
label: Page | label: Page | ||||
label_plurial: Pages | label_plurial: Pages | ||||
default: | default: | ||||
file: Fichier | file: Fichier | ||||
status: Statut | status: Statut | ||||
email: Email | email: Email | ||||
metaTitle: Meta title | |||||
metaTitle_help: Affiché dans les résultats de recherche Google | |||||
metaDescription: Meta description | |||||
metaDescription_help: Affiché dans les résultats de recherche Google | |||||
oldUrls: Anciennes urls | |||||
devAlias: Alias | |||||
gallery: Galerie | |||||
panels: | panels: | ||||
general: Général | general: Général | ||||
configuration: Configuration | configuration: Configuration | ||||
gallery: Galerie | gallery: Galerie | ||||
seo: Référencement | seo: Référencement | ||||
action: | |||||
save: Sauvegarder | |||||
form: | form: | ||||
change_password: | change_password: | ||||
current_password: Mot de passe actuel | current_password: Mot de passe actuel |
$this->translator = $translator; | $this->translator = $translator; | ||||
} | } | ||||
public function transAction($action) | |||||
{ | |||||
return $this->trans('action.' . $action); | |||||
} | |||||
public function transMenu($menu) | |||||
{ | |||||
return $this->trans('menu.' . $menu); | |||||
} | |||||
public function transFlashMessage($name) | |||||
{ | |||||
return $this->trans('flash_message.' . $name); | |||||
} | |||||
public function transField($fieldName, $entityClass): string | public function transField($fieldName, $entityClass): string | ||||
{ | { | ||||
return $this->transEntityThenDefault( | return $this->transEntityThenDefault( | ||||
{ | { | ||||
$entityName = $this->getEntityName($entityClass); | $entityName = $this->getEntityName($entityClass); | ||||
$paramsTranslation = [] ; | |||||
$paramsTranslation = []; | |||||
if($entityName) { | |||||
$baseIdEntityLabel = 'entity.' . $entityName ; | |||||
if ($entityName) { | |||||
$baseIdEntityLabel = 'entity.' . $entityName; | |||||
$paramsTranslation = [ | $paramsTranslation = [ | ||||
'%label%' => $this->trans($baseIdEntityLabel . '.label'), | '%label%' => $this->trans($baseIdEntityLabel . '.label'), | ||||
'%label_plurial%' => $this->trans($baseIdEntityLabel . '.label_plurial'), | '%label_plurial%' => $this->trans($baseIdEntityLabel . '.label_plurial'), | ||||
] ; | |||||
]; | |||||
} | } | ||||
if (isset($params['id'])) { | if (isset($params['id'])) { | ||||
private function buildTransIdField($fieldName, $entityClass, $default = false): string | private function buildTransIdField($fieldName, $entityClass, $default = false): string | ||||
{ | { | ||||
if ($default) { | |||||
$entityName = 'default'; | |||||
} else { | |||||
$entityName = $this->getEntityName($entityClass); | |||||
} | |||||
return 'entity.' . $entityName . '.fields.' . $fieldName; | |||||
return $this->buildTransIdEntitySection($fieldName, $entityClass, 'fields', $default); | |||||
} | } | ||||
private function buildTransIdPanel($panelName, $entityClass, $default = false): string | private function buildTransIdPanel($panelName, $entityClass, $default = false): string | ||||
{ | |||||
return $this->buildTransIdEntitySection($panelName, $entityClass, 'panels', $default); | |||||
} | |||||
private function buildTransIdEntitySection($name, $entityClass, $entitySection, $default): string | |||||
{ | { | ||||
if ($default) { | if ($default) { | ||||
$entityName = 'default'; | $entityName = 'default'; | ||||
$entityName = $this->getEntityName($entityClass); | $entityName = $this->getEntityName($entityClass); | ||||
} | } | ||||
return 'entity.' . $entityName . '.panels.' . $panelName; | |||||
return 'entity.' . $entityName . '.' . $entitySection . '.' . $name; | |||||
} | } | ||||
private function trans($id, $params = [], $domain = self::DOMAIN): string | private function trans($id, $params = [], $domain = self::DOMAIN): string | ||||
private function getEntityName($entityClass): string | private function getEntityName($entityClass): string | ||||
{ | { | ||||
if(is_object($entityClass)) { | |||||
$entityClass = get_class($entityClass) ; | |||||
if (is_object($entityClass)) { | |||||
$entityClass = get_class($entityClass); | |||||
} | } | ||||
if(is_string($entityClass)) { | |||||
if (is_string($entityClass)) { | |||||
$entityNameExplode = explode('\\', $entityClass); | $entityNameExplode = explode('\\', $entityClass); | ||||
return strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||||
return $entityNameExplode[count($entityNameExplode) - 1]; | |||||
} | } | ||||
return 'default' ; | |||||
return 'default'; | |||||
} | } | ||||
} | } | ||||
new TwigFilter('lc_trans_admin_panel', [$this, 'lcTransAdminPanel']), | new TwigFilter('lc_trans_admin_panel', [$this, 'lcTransAdminPanel']), | ||||
new TwigFilter('lc_trans_admin_menu', [$this, 'lcTransAdminMenu']), | new TwigFilter('lc_trans_admin_menu', [$this, 'lcTransAdminMenu']), | ||||
new TwigFilter('lc_trans_admin_title', [$this, 'lcTransAdminTitle']), | new TwigFilter('lc_trans_admin_title', [$this, 'lcTransAdminTitle']), | ||||
new TwigFilter('lc_trans_admin_action', [$this, 'lcTransAdminAction']), | |||||
]; | ]; | ||||
} | } | ||||
public function lcTransAdminMenu($menuName) | public function lcTransAdminMenu($menuName) | ||||
{ | { | ||||
return $this->translator->trans('menu.' . $menuName, [], 'admin');; | |||||
return $this->translatorAdmin->transMenu($menuName);; | |||||
} | |||||
public function lcTransAdminAction($actionName) | |||||
{ | |||||
return $this->translatorAdmin->transAction($actionName);; | |||||
} | } | ||||
public function lcTransAdminTitle($pageName, $entityClass = null, $params = []) | public function lcTransAdminTitle($pageName, $entityClass = null, $params = []) |