namespace Lc\SovBundle\Controller\Admin; | namespace Lc\SovBundle\Controller\Admin; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | |||||
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; | ||||
class UserController extends AbstractController | class UserController extends AbstractController | ||||
{ | { | ||||
protected $em; | protected $em; | ||||
public function __construct(EntityManager $em) | public function __construct(EntityManager $em) | ||||
if ($form->isSubmitted() && $form->isValid()) { | if ($form->isSubmitted() && $form->isValid()) { | ||||
$user = $form->getData(); | $user = $form->getData(); | ||||
$plainPassword = $form->get('plainPassword')->getData(); | |||||
$plainPassword = $form->get('plain_password')->getData(); | |||||
// @TODO : créer UserManager | // @TODO : créer UserManager | ||||
$newPasswordEncoded = $passwordEncoder->encodePassword($user, $plainPassword); | $newPasswordEncoded = $passwordEncoder->encodePassword($user, $plainPassword); |
use Symfony\Component\Form\FormBuilderInterface; | use Symfony\Component\Form\FormBuilderInterface; | ||||
use Symfony\Component\OptionsResolver\OptionsResolver; | use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; | use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; | ||||
use Symfony\Component\Translation\TranslatableMessage; | |||||
use Symfony\Component\Validator\Constraints\NotBlank; | use Symfony\Component\Validator\Constraints\NotBlank; | ||||
class ChangePasswordFormType extends AbstractType | class ChangePasswordFormType extends AbstractType | ||||
'current_password', | 'current_password', | ||||
PasswordType::class, | PasswordType::class, | ||||
[ | [ | ||||
'label' => 'Mot de passe actuel', | |||||
'label' => 'form.change_password.current_password', | |||||
'mapped' => false, | 'mapped' => false, | ||||
'constraints' => [ | 'constraints' => [ | ||||
new NotBlank(), | new NotBlank(), | ||||
[ | [ | ||||
'type' => PasswordType::class, | 'type' => PasswordType::class, | ||||
'mapped' => false, | 'mapped' => false, | ||||
'first_options' => ['label' => 'Nouveau mot de passe'], | |||||
'second_options' => ['label' => 'Nouveau mot de passe (confirmation)'], | |||||
'first_options' => ['label' => 'form.change_password.new_password'], | |||||
'second_options' => ['label' => 'form.change_password.new_password_repeat'], | |||||
'invalid_message' => 'Les deux mots de passe ne correspondent pas.', | 'invalid_message' => 'Les deux mots de passe ne correspondent pas.', | ||||
] | ] | ||||
); | ); | ||||
'submit', | 'submit', | ||||
SubmitType::class, | SubmitType::class, | ||||
array( | array( | ||||
'label' => 'Sauvegarder' | |||||
'label' => new TranslatableMessage('action.save', [], 'admin') | |||||
) | ) | ||||
); | ); | ||||
} | } |
use Symfony\Component\Form\Extension\Core\Type\TextType; | use Symfony\Component\Form\Extension\Core\Type\TextType; | ||||
use Symfony\Component\Form\FormBuilderInterface; | use Symfony\Component\Form\FormBuilderInterface; | ||||
use Symfony\Component\OptionsResolver\OptionsResolver; | use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
use Symfony\Component\Translation\TranslatableMessage; | |||||
class ProfileFormType extends AbstractType | class ProfileFormType extends AbstractType | ||||
{ | { | ||||
protected $em ; | |||||
protected $em; | |||||
public function __construct(EntityManager $em) | public function __construct(EntityManager $em) | ||||
{ | { | ||||
$this->em = $em ; | |||||
$this->em = $em; | |||||
} | } | ||||
public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
{ | { | ||||
$entityName = $this->em->getEntityName(UserInterface::class) ; | |||||
$entityName = $this->em->getEntityName(UserInterface::class); | |||||
$builder->add( | $builder->add( | ||||
'firstname', | 'firstname', | ||||
TextType::class, | |||||
array( | |||||
'label' => 'Prénom' | |||||
) | |||||
TextType::class | |||||
); | ); | ||||
$builder->add( | $builder->add( | ||||
'lastname', | 'lastname', | ||||
TextType::class, | |||||
array( | |||||
'label' => 'Nom' | |||||
) | |||||
TextType::class | |||||
); | ); | ||||
$builder->add( | $builder->add( | ||||
'email', | 'email', | ||||
EmailType::class, | |||||
array( | |||||
'label' => 'Email' | |||||
) | |||||
EmailType::class | |||||
); | ); | ||||
if(property_exists($entityName, 'phone')) { | |||||
if (property_exists($entityName, 'phone')) { | |||||
$builder->add( | $builder->add( | ||||
'phone', | 'phone', | ||||
TextType::class, | |||||
array( | |||||
'label' => 'Téléphone' | |||||
) | |||||
TextType::class | |||||
); | ); | ||||
} | } | ||||
$builder->add( | $builder->add( | ||||
'submit', | 'submit', | ||||
SubmitType::class, | SubmitType::class, | ||||
array( | |||||
'label' => 'Sauvegarder' | |||||
) | |||||
[ | |||||
'label' => new TranslatableMessage('action.save', [], 'admin') | |||||
] | |||||
); | ); | ||||
} | } | ||||
user: | user: | ||||
label: Utilisateur | label: Utilisateur | ||||
label_plurial: Utilisateurs | label_plurial: Utilisateurs | ||||
fields: | |||||
firstname: Prénom | |||||
lastname: Nom | |||||
page: | page: | ||||
label: Page | label: Page | ||||
label_plurial: Pages | label_plurial: Pages | ||||
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: | |||||
change_password: | |||||
current_password: Mot de passe actuel | |||||
new_password: Nouveau mot de passe | |||||
new_password_repeat: Nouveau mot de passe (confirmer) |
</div> | </div> | ||||
{% endif %} | {% endif %} | ||||
{% set help_message = name|lc_trans_admin_help(ea.getEntity().getFqcn()) %} | |||||
{% set help_message = name|lc_trans_admin_help(form.parent.vars.data) %} | |||||
{% if help_message != '' %} | {% if help_message != '' %} | ||||
<small class="form-help">{{ help_message }}</small> | <small class="form-help">{{ help_message }}</small> | ||||
{% endif %} | {% endif %} | ||||
{%- endif -%} | {%- endif -%} | ||||
{%- endif -%} | {%- endif -%} | ||||
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (translation_domain is same as(false)) ? label : label|lower|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</{{ element|default('label') }}> | |||||
{# <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (translation_domain is same as(false)) ? label : label|lower|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</{{ element|default('label') }}> #} | |||||
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|lc_trans_admin_field(form.parent.vars.data) }}</{{ element|default('label') }}> | |||||
{%- endif -%} | {%- endif -%} | ||||
{%- endblock form_label %} | {%- endblock form_label %} | ||||
$entityName = $this->getEntityName($entityClass); | $entityName = $this->getEntityName($entityClass); | ||||
} | } | ||||
return 'entity.' . $entityName . '.panels.' . $panelName; | return 'entity.' . $entityName . '.panels.' . $panelName; | ||||
} | } | ||||
private function getEntityName($entityClass): string | private function getEntityName($entityClass): string | ||||
{ | { | ||||
$entityNameExplode = explode('\\', $entityClass); | |||||
return strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||||
if(is_object($entityClass)) { | |||||
$entityClass = get_class($entityClass) ; | |||||
} | |||||
if(is_string($entityClass)) { | |||||
$entityNameExplode = explode('\\', $entityClass); | |||||
return strtolower($entityNameExplode[count($entityNameExplode) - 1]); | |||||
} | |||||
return 'default' ; | |||||
} | } | ||||
} | } | ||||