@@ -40,6 +40,7 @@ use Lc\SovBundle\Doctrine\Extension\TreeInterface; | |||
use Lc\SovBundle\Field\CollectionField; | |||
use Lc\SovBundle\Field\GalleryManagerField; | |||
use Lc\SovBundle\Form\Type\Crud\PositionType; | |||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
@@ -51,13 +52,20 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
{ | |||
protected $session; | |||
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->request = $request; | |||
$this->em = $em; | |||
$this->twig = $twig; | |||
$this->translatorAdmin = $translatorAdmin; | |||
} | |||
public function configureActions(Actions $actions): Actions | |||
@@ -79,22 +87,27 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
$actionsArray[Crud::PAGE_INDEX] = [ | |||
Action::NEW => [ | |||
'icon' => 'plus', | |||
'label' => 'Créer', | |||
'label' => $this->translatorAdmin->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' => 'Éditer') | |||
'html_attributes' => array( | |||
'data-toggle' => 'tooltip', | |||
'title' => $this->translatorAdmin->transAction('edit') | |||
) | |||
], | |||
Action::DELETE => [ | |||
'icon' => 'trash', | |||
'dropdown' => true, | |||
'label' => $this->translatorAdmin->transAction('delete') | |||
], | |||
Action::BATCH_DELETE => [ | |||
'class' => 'btn btn-sm btn-danger', | |||
'icon' => 'trash', | |||
'label' => $this->translatorAdmin->transAction('delete') | |||
], | |||
]; | |||
@@ -103,19 +116,23 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
$actionSaveAndReturn = [ | |||
'add_class' => 'float-right', | |||
'icon' => 'check', | |||
'label' => $this->translatorAdmin->transAction('save_and_return') | |||
]; | |||
$actionIndex = [ | |||
'icon' => 'chevron-left', | |||
'class' => 'btn btn-link', | |||
'label' => $this->translatorAdmin->transAction('back_index') | |||
]; | |||
$actionsArray[Crud::PAGE_EDIT] = [ | |||
Action::SAVE_AND_CONTINUE => [ | |||
'class' => 'btn btn-info float-right', | |||
'label' => $this->translatorAdmin->transAction('save_and_continue') | |||
], | |||
Action::DELETE => [ | |||
'icon' => 'trash', | |||
'class' => 'btn btn-outline-danger action-delete', | |||
'label' => $this->translatorAdmin->transAction('delete') | |||
], | |||
Action::SAVE_AND_RETURN => $actionSaveAndReturn, | |||
Action::INDEX => $actionIndex, | |||
@@ -124,6 +141,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
$actionsArray[Crud::PAGE_NEW] = [ | |||
Action::SAVE_AND_ADD_ANOTHER => [ | |||
'class' => 'btn btn-info float-right', | |||
'label' => $this->translatorAdmin->transAction('save_and_add_another') | |||
], | |||
Action::SAVE_AND_RETURN => $actionSaveAndReturn, | |||
Action::INDEX => $actionIndex, | |||
@@ -134,7 +152,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
$actions->add(Crud::PAGE_NEW, Action::INDEX); | |||
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') | |||
->setCssClass('btn btn-sm btn-success') | |||
->createAsGlobalAction(); | |||
@@ -144,14 +162,22 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
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) | |||
->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', 'Retour au parent', 'fa fa-chevron-left') | |||
$backParentAction = Action::new( | |||
'index_parent', | |||
$this->translatorAdmin->transAction('index_parent'), | |||
'fa fa-chevron-left' | |||
) | |||
->linkToCrudAction(Action::INDEX) | |||
->setCssClass('btn btn-sm btn-info') | |||
->createAsGlobalAction(); | |||
@@ -246,12 +272,8 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
if ($this->isInstanceOf(SortableInterface::class)) { | |||
$seoPanel = [ | |||
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') | |||
->setFormTypeOption('entry_type', TextType::class)->setLabel( | |||
'Anciennes urls du document' | |||
@@ -333,7 +355,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
$url = $this->get(AdminUrlGenerator::class) | |||
->setAction(Action::INDEX) | |||
->generateUrl(); | |||
$this->addFlash('success', 'Position modifié', array()); | |||
$this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array()); | |||
return $this->redirect($url); | |||
} | |||
@@ -418,14 +440,14 @@ abstract class AbstractCrudController extends EaAbstractCrudController | |||
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) | |||
if ($context->getRequest()->isXmlHttpRequest()) { | |||
$this->session->getFlashBag()->clear() ; | |||
$this->session->getFlashBag()->clear(); | |||
} | |||
return $response ; | |||
return $response; | |||
} | |||
public function isInstanceOf(string $interfaceName): bool |
@@ -13,6 +13,7 @@ namespace Lc\SovBundle\Form\Type\User; | |||
use Lc\SovBundle\Doctrine\EntityManager; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\PasswordType; | |||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType; | |||
@@ -26,11 +27,13 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
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; | |||
} | |||
/** | |||
@@ -75,7 +78,7 @@ class ChangePasswordFormType extends AbstractType | |||
'submit', | |||
SubmitType::class, | |||
array( | |||
'label' => new TranslatableMessage('action.save', [], 'admin') | |||
'label' => $this->translatorAdmin->transAction('save') | |||
) | |||
); | |||
} |
@@ -6,6 +6,7 @@ use Lc\SovBundle\DataTransformer\FileManagerTypeToDataTransformer; | |||
use Lc\SovBundle\Doctrine\EntityManager; | |||
use Lc\SovBundle\Model\File\FileInterface; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\EmailType; | |||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |||
@@ -17,10 +18,12 @@ use Symfony\Component\Translation\TranslatableMessage; | |||
class ProfileFormType extends AbstractType | |||
{ | |||
protected $em; | |||
protected $translatorAdmin; | |||
public function __construct(EntityManager $em) | |||
public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin) | |||
{ | |||
$this->em = $em; | |||
$this->translatorAdmin = $translatorAdmin; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
@@ -53,7 +56,7 @@ class ProfileFormType extends AbstractType | |||
'submit', | |||
SubmitType::class, | |||
[ | |||
'label' => new TranslatableMessage('action.save', [], 'admin') | |||
'label' => $this->translatorAdmin->transAction('save') | |||
] | |||
); | |||
} |
@@ -1,20 +1,12 @@ | |||
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: | |||
dashboard: Tableau de bord | |||
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: | |||
dashboard: Tableau de bord | |||
@@ -27,14 +19,33 @@ title: | |||
profile: Mes informations personnelles | |||
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: | |||
user: | |||
User: | |||
label: Utilisateur | |||
label_plurial: Utilisateurs | |||
fields: | |||
firstname: Prénom | |||
lastname: Nom | |||
page: | |||
Page: | |||
label: Page | |||
label_plurial: Pages | |||
default: | |||
@@ -47,15 +58,20 @@ entity: | |||
file: Fichier | |||
status: Statut | |||
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: | |||
general: Général | |||
configuration: Configuration | |||
gallery: Galerie | |||
seo: Référencement | |||
action: | |||
save: Sauvegarder | |||
form: | |||
change_password: | |||
current_password: Mot de passe actuel |
@@ -16,6 +16,21 @@ class TranslatorAdmin | |||
$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 | |||
{ | |||
return $this->transEntityThenDefault( | |||
@@ -47,14 +62,14 @@ class TranslatorAdmin | |||
{ | |||
$entityName = $this->getEntityName($entityClass); | |||
$paramsTranslation = [] ; | |||
$paramsTranslation = []; | |||
if($entityName) { | |||
$baseIdEntityLabel = 'entity.' . $entityName ; | |||
if ($entityName) { | |||
$baseIdEntityLabel = 'entity.' . $entityName; | |||
$paramsTranslation = [ | |||
'%label%' => $this->trans($baseIdEntityLabel . '.label'), | |||
'%label_plurial%' => $this->trans($baseIdEntityLabel . '.label_plurial'), | |||
] ; | |||
]; | |||
} | |||
if (isset($params['id'])) { | |||
@@ -88,16 +103,15 @@ class TranslatorAdmin | |||
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 | |||
{ | |||
return $this->buildTransIdEntitySection($panelName, $entityClass, 'panels', $default); | |||
} | |||
private function buildTransIdEntitySection($name, $entityClass, $entitySection, $default): string | |||
{ | |||
if ($default) { | |||
$entityName = 'default'; | |||
@@ -105,7 +119,7 @@ class TranslatorAdmin | |||
$entityName = $this->getEntityName($entityClass); | |||
} | |||
return 'entity.' . $entityName . '.panels.' . $panelName; | |||
return 'entity.' . $entityName . '.' . $entitySection . '.' . $name; | |||
} | |||
private function trans($id, $params = [], $domain = self::DOMAIN): string | |||
@@ -115,16 +129,16 @@ class TranslatorAdmin | |||
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); | |||
return strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||
return $entityNameExplode[count($entityNameExplode) - 1]; | |||
} | |||
return 'default' ; | |||
return 'default'; | |||
} | |||
} | |||
@@ -66,6 +66,7 @@ class TwigExtension extends AbstractExtension | |||
new TwigFilter('lc_trans_admin_panel', [$this, 'lcTransAdminPanel']), | |||
new TwigFilter('lc_trans_admin_menu', [$this, 'lcTransAdminMenu']), | |||
new TwigFilter('lc_trans_admin_title', [$this, 'lcTransAdminTitle']), | |||
new TwigFilter('lc_trans_admin_action', [$this, 'lcTransAdminAction']), | |||
]; | |||
} | |||
@@ -96,7 +97,12 @@ class TwigExtension extends AbstractExtension | |||
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 = []) |