namespace Lc\SovBundle\Controller\Admin; | namespace Lc\SovBundle\Controller\Admin; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | |||||
use Lc\SovBundle\Doctrine\EntityManager; | use Lc\SovBundle\Doctrine\EntityManager; | ||||
use Lc\SovBundle\Form\Type\User\ChangePasswordFormType; | use Lc\SovBundle\Form\Type\User\ChangePasswordFormType; | ||||
use Lc\SovBundle\Form\Type\User\ProfileFormType; | use Lc\SovBundle\Form\Type\User\ProfileFormType; | ||||
use Lc\SovBundle\Model\User\User; | |||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
use Symfony\Component\HttpFoundation\Response; | use Symfony\Component\HttpFoundation\Response; | ||||
return $this->render( | return $this->render( | ||||
'@LcSov/user/profile.html.twig', | '@LcSov/user/profile.html.twig', | ||||
[ | [ | ||||
'form' => $form->createView() | |||||
'form' => $form->createView(), | |||||
] | ] | ||||
); | ); | ||||
} | } |
update: Le contenu "%name%" a été mis à jour avec succès. | update: Le contenu "%name%" a été mis à jour avec succès. | ||||
delete: Le contenu "%name%" a été supprimé avec succès. | delete: Le contenu "%name%" a été supprimé avec succès. | ||||
form: | |||||
title: | |||||
edit: Modifier "%name%" | |||||
new: Ajouter "%name%" | |||||
menu: | menu: | ||||
dashboard: Tableau de bord | dashboard: Tableau de bord | ||||
page: Pages | |||||
user: | |||||
label: Utilisateurs | |||||
childs: | |||||
index: Liste | |||||
account: | account: | ||||
label: Mon compte | label: Mon compte | ||||
childs: | childs: | ||||
profile: Informations personnelles | profile: Informations personnelles | ||||
password: Mot de passe | password: Mot de passe | ||||
title: | |||||
dashboard: Tableau de bord | |||||
index: '%label_plurial%' | |||||
sort: Ordonner "%label_plurial%" | |||||
new: Ajouter "%label%" | |||||
edit: Modifier "%label%" (#%id%) | |||||
detail: Voir "%label%" (#%id%) | |||||
account: | |||||
profile: Mes informations personnelles | |||||
change_password: Changer de mot de passe | |||||
entity: | entity: | ||||
user: | |||||
label: Utilisateur | |||||
label_plurial: Utilisateurs | |||||
page: | |||||
label: Page | |||||
label_plurial: Pages | |||||
default: | default: | ||||
fields: | fields: | ||||
title: Titre | title: Titre | ||||
description_help: Description help | description_help: Description help | ||||
file: Fichier | file: Fichier | ||||
status: Statut | status: Statut | ||||
email: Email | |||||
panels: | panels: | ||||
general: Général | general: Général | ||||
configuration: Configuration | configuration: Configuration |
{% block body_class 'ea-edit ea-edit-' ~ entity.name %} | {% block body_class 'ea-edit ea-edit-' ~ entity.name %} | ||||
{% block content_title %} | {% block content_title %} | ||||
{{ 'edit'|lc_trans_admin_title(ea.getEntity().getFqcn()) }} | |||||
{{ 'edit'|lc_trans_admin_title(ea.getEntity().getFqcn(), {id: ea.getEntity().getInstance().getId()}) }} | |||||
{% endblock %} | {% endblock %} | ||||
{% block delete_form %} | {% block delete_form %} |
</div> | </div> | ||||
{% endif %} | {% endif %} | ||||
{% set help_message = name|lc_trans_admin_field(ea.getEntity().getFqcn(), true) %} | |||||
{% set help_message = name|lc_trans_admin_help(ea.getEntity().getFqcn()) %} | |||||
{% if help_message != '' %} | {% if help_message != '' %} | ||||
<small class="form-help">{{ help_message }}</small> | <small class="form-help">{{ help_message }}</small> | ||||
{% endif %} | {% endif %} | ||||
{% if panel_config.icon|default(false) %} | {% if panel_config.icon|default(false) %} | ||||
<i class="{{ panel_config.icon }}"></i> | <i class="{{ panel_config.icon }}"></i> | ||||
{% endif %} | {% endif %} | ||||
{{ panel_config.label|raw }} | |||||
{{ panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn()) }} | |||||
{% if collapsible %} | {% if collapsible %} | ||||
</a> | </a> |
{{ 'new'|lc_trans_admin_title(ea.getEntity().getFqcn()) }} | {{ 'new'|lc_trans_admin_title(ea.getEntity().getFqcn()) }} | ||||
{% endblock %} | {% endblock %} | ||||
{% block body_javascript %} | {% block body_javascript %} | ||||
{{ parent() }} | {{ parent() }} | ||||
{% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %} | {% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %} | ||||
{% block content_title %} | {% block content_title %} | ||||
Édition position | |||||
{{ 'sort'|lc_trans_admin_title(ea.getEntity().getFqcn()) }} | |||||
{% endblock %} | {% endblock %} | ||||
{% block content_breadcrumb %} | {% block content_breadcrumb %} | ||||
{{ include('@LcSov/adminlte/block/breadcrumb.html.twig') }} | {{ include('@LcSov/adminlte/block/breadcrumb.html.twig') }} | ||||
{% endblock content_breadcrumb %} | {% endblock content_breadcrumb %} |
{% extends '@LcSov/adminlte/layout.html.twig' %} | {% extends '@LcSov/adminlte/layout.html.twig' %} | ||||
{% block content_title 'SovBundle' %} | |||||
{% block content_title %} | |||||
{{ 'dashboard'|lc_trans_admin_title }} | |||||
{% endblock %} | |||||
{% block main %} | {% block main %} | ||||
Tableau de bord par défaut. | Tableau de bord par défaut. |
{% extends '@LcSov/adminlte/layout.html.twig' %} | {% extends '@LcSov/adminlte/layout.html.twig' %} | ||||
{% block content_title %} | {% block content_title %} | ||||
Changer de mot de passe | |||||
{{ 'account.change_password'|lc_trans_admin_title }} | |||||
{% endblock %} | {% endblock %} | ||||
{% block main %} | {% block main %} |
{% extends '@LcSov/adminlte/layout.html.twig' %} | {% extends '@LcSov/adminlte/layout.html.twig' %} | ||||
{% block content_title %} | {% block content_title %} | ||||
Mes informations personnelles | |||||
{{ 'account.profile'|lc_trans_admin_title }} | |||||
{% endblock %} | {% endblock %} | ||||
{% block main %} | {% block main %} |
<?php | |||||
namespace Lc\SovBundle\Translation; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | |||||
use Symfony\Contracts\Translation\TranslatorInterface; | |||||
class TranslatorAdmin | |||||
{ | |||||
protected $translator; | |||||
const DOMAIN = 'admin'; | |||||
public function __construct(TranslatorInterface $translator) | |||||
{ | |||||
$this->translator = $translator; | |||||
} | |||||
public function transField($fieldName, $entityClass): string | |||||
{ | |||||
return $this->transEntityThenDefault( | |||||
$this->buildTransIdField($fieldName, $entityClass), | |||||
$this->buildTransIdField($fieldName, $entityClass, true) | |||||
); | |||||
} | |||||
public function transHelp($fieldName, $entityClass): string | |||||
{ | |||||
$fieldName = $fieldName . '_help'; | |||||
return $this->transEntityThenDefault( | |||||
$this->buildTransIdField($fieldName, $entityClass), | |||||
$this->buildTransIdField($fieldName, $entityClass, true), | |||||
true | |||||
); | |||||
} | |||||
public function transPanel($panelName, $entityClass): string | |||||
{ | |||||
return $this->transEntityThenDefault( | |||||
$this->buildTransIdPanel($panelName, $entityClass), | |||||
$this->buildTransIdPanel($panelName, $entityClass, true) | |||||
); | |||||
} | |||||
public function transTitle($pageName, $entityClass = null, $params = []) | |||||
{ | |||||
$entityName = $this->getEntityName($entityClass); | |||||
$paramsTranslation = [] ; | |||||
if($entityName) { | |||||
$baseIdEntityLabel = 'entity.' . $entityName ; | |||||
$paramsTranslation = [ | |||||
'%label%' => $this->trans($baseIdEntityLabel . '.label'), | |||||
'%label_plurial%' => $this->trans($baseIdEntityLabel . '.label_plurial'), | |||||
] ; | |||||
} | |||||
if (isset($params['id'])) { | |||||
$paramsTranslation['%id%'] = $params['id']; | |||||
} | |||||
return $this->trans( | |||||
'title.' . $pageName, | |||||
$paramsTranslation | |||||
); | |||||
} | |||||
private function transEntityThenDefault($idTranslationEntity, $idTranslationDefault, $returnEmpty = false): string | |||||
{ | |||||
$translation = $this->trans($idTranslationEntity); | |||||
if ($translation == $idTranslationEntity) { | |||||
$translation = $this->trans($idTranslationDefault); | |||||
if ($translation == $idTranslationDefault) { | |||||
if ($returnEmpty) { | |||||
$translation = ''; | |||||
} else { | |||||
$translation = $idTranslationEntity; | |||||
} | |||||
} | |||||
} | |||||
return $translation; | |||||
} | |||||
private function buildTransIdField($fieldName, $entityClass, $default = false): string | |||||
{ | |||||
if ($default) { | |||||
$entityName = 'default'; | |||||
} else { | |||||
$entityName = $this->getEntityName($entityClass); | |||||
} | |||||
return 'entity.' . $entityName . '.fields.' . $fieldName; | |||||
} | |||||
private function buildTransIdPanel($panelName, $entityClass, $default = false): string | |||||
{ | |||||
if ($default) { | |||||
$entityName = 'default'; | |||||
} else { | |||||
$entityName = $this->getEntityName($entityClass); | |||||
} | |||||
return 'entity.' . $entityName . '.panels.' . $panelName; | |||||
} | |||||
private function trans($id, $params = [], $domain = self::DOMAIN): string | |||||
{ | |||||
return $this->translator->trans($id, $params, $domain); | |||||
} | |||||
private function getEntityName($entityClass): string | |||||
{ | |||||
$entityNameExplode = explode('\\', $entityClass); | |||||
return strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||||
} | |||||
} | |||||
?> |
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | |||||
use Liip\ImagineBundle\Imagine\Cache\CacheManager; | use Liip\ImagineBundle\Imagine\Cache\CacheManager; | ||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||||
use Symfony\Component\HttpFoundation\RequestStack; | use Symfony\Component\HttpFoundation\RequestStack; | ||||
protected $requestStack; | protected $requestStack; | ||||
protected $router; | protected $router; | ||||
protected $translator; | protected $translator; | ||||
protected $translatorAdmin; | |||||
public function __construct( | public function __construct( | ||||
KernelInterface $kernel, | KernelInterface $kernel, | ||||
EntityManagerInterface $entityManager, | EntityManagerInterface $entityManager, | ||||
RequestStack $requestStack, | RequestStack $requestStack, | ||||
UrlGeneratorInterface $router, | UrlGeneratorInterface $router, | ||||
TranslatorInterface $translator | |||||
TranslatorInterface $translator, | |||||
TranslatorAdmin $translatorAdmin | |||||
) { | ) { | ||||
$this->kernel = $kernel; | $this->kernel = $kernel; | ||||
$this->parameterBag = $parameterBag; | $this->parameterBag = $parameterBag; | ||||
$this->requestStack = $requestStack; | $this->requestStack = $requestStack; | ||||
$this->router = $router; | $this->router = $router; | ||||
$this->translator = $translator; | $this->translator = $translator; | ||||
$this->translatorAdmin = $translatorAdmin; | |||||
} | } | ||||
public function getFunctions() | public function getFunctions() | ||||
return [ | return [ | ||||
new TwigFilter('lc_cache', [$this, 'lcCache']), | new TwigFilter('lc_cache', [$this, 'lcCache']), | ||||
new TwigFilter('lc_trans_admin_field', [$this, 'lcTransAdminField']), | new TwigFilter('lc_trans_admin_field', [$this, 'lcTransAdminField']), | ||||
new TwigFilter('lc_trans_admin_help', [$this, 'lcTransAdminHelp']), | |||||
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']), | ||||
} | } | ||||
} | } | ||||
public function lcTransAdminField($fieldName, $entityClass, $isHelp = false) | |||||
public function lcTransAdminField($fieldName, $entityClass) | |||||
{ | { | ||||
if ($isHelp) { | |||||
$fieldName = $fieldName . '_help'; | |||||
} | |||||
$entityName = $this->getEntityName($entityClass) ; | |||||
$entityLabel = 'entity.' . $entityName . '.fields.' . $fieldName; | |||||
$translatedLabel = $this->translator->trans($entityLabel, [], 'admin'); | |||||
if ($translatedLabel == $entityLabel) { | |||||
$defaultLabel = 'entity.default.fields.' . $fieldName; | |||||
$translatedLabel = $this->translator->trans($defaultLabel, [], 'admin'); | |||||
if ($translatedLabel == $defaultLabel) { | |||||
if ($isHelp) { | |||||
$translatedLabel = ''; | |||||
} else { | |||||
$translatedLabel = $entityLabel; | |||||
} | |||||
} | |||||
} | |||||
return $translatedLabel; | |||||
return $this->translatorAdmin->transField($fieldName, $entityClass) ; | |||||
} | } | ||||
public function lcTransAdminPanel($panelName, $entityClass) | |||||
public function lcTransAdminHelp($fieldName, $entityClass) | |||||
{ | { | ||||
$entityName = $this->getEntityName($entityClass) ; | |||||
$panelLabel = 'entity.' . $entityName . '.panels.' . $panelName; | |||||
$translatedLabel = $this->translator->trans($panelLabel, [], 'admin'); | |||||
if ($translatedLabel == $panelLabel) { | |||||
$defaultLabel = 'entity.default.panels.' . $panelName; | |||||
$translatedLabel = $this->translator->trans($defaultLabel, [], 'admin'); | |||||
if ($translatedLabel == $defaultLabel) { | |||||
$translatedLabel = $panelLabel; | |||||
} | |||||
} | |||||
return $translatedLabel; | |||||
return $this->translatorAdmin->transHelp($fieldName, $entityClass) ; | |||||
} | } | ||||
public function lcTransAdminMenu($menuName) | |||||
public function lcTransAdminPanel($panelName, $entityClass) | |||||
{ | { | ||||
$menuLabel = 'menu.'.$menuName; | |||||
$translatedLabel = $this->translator->trans($menuLabel, [], 'admin'); | |||||
return $translatedLabel ; | |||||
return $this->translatorAdmin->transPanel($panelName, $entityClass) ; | |||||
} | } | ||||
public function lcTransAdminTitle($pageName, $entityClass) | |||||
public function lcTransAdminMenu($menuName) | |||||
{ | { | ||||
$entityName = $this->getEntityName($entityClass) ; | |||||
$translatedLabel = '' ; | |||||
if(Crud::PAGE_INDEX == $pageName) { | |||||
$titleLabel = 'entity.'.$entityName.'.label_plurial' ; | |||||
$translatedLabel = $this->translator->trans($titleLabel, [], 'admin'); | |||||
} | |||||
elseif(Crud::PAGE_EDIT == $pageName) { | |||||
$entityLabel = 'entity.'.$entityName.'.label' ; | |||||
$translatedEntityLabel = $this->translator->trans($entityLabel, [],'admin'); | |||||
$translatedLabel = $this->translator->trans('form.title.edit', ['%name%' => $translatedEntityLabel], 'admin'); | |||||
} | |||||
elseif(Crud::PAGE_NEW == $pageName) { | |||||
$entityLabel = 'entity.'.$entityName.'.label' ; | |||||
$translatedEntityLabel = $this->translator->trans($entityLabel, [], 'admin'); | |||||
$translatedLabel = $this->translator->trans('form.title.new', ['%name%' => $translatedEntityLabel], 'admin'); | |||||
} | |||||
return $translatedLabel ; | |||||
return $this->translator->trans('menu.' . $menuName, [], 'admin');; | |||||
} | } | ||||
public function getEntityName($entityClass) | |||||
public function lcTransAdminTitle($pageName, $entityClass = null, $params = []) | |||||
{ | { | ||||
$entityNameExplode = explode('\\', $entityClass); | |||||
$entityName = strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||||
return $entityName ; | |||||
return $this->translatorAdmin->transTitle($pageName, $entityClass, $params) ; | |||||
} | } | ||||
public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') | public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') |