Fixed Deprecations: EasyAdmin and Symfony Security

This commit is contained in:
2025-10-23 22:13:19 +02:00
parent 850e8afaa1
commit fe2bc7b78c
3 changed files with 12 additions and 10 deletions
+9 -9
View File
@@ -28,18 +28,18 @@ class UserCrudController extends AbstractCrudController
public function configureFields(string $pageName): iterable public function configureFields(string $pageName): iterable
{ {
yield TextField::new ('username'); yield TextField::new('username');
yield TextField::new ('username')->onlyWhenUpdating()->setDisabled(true); yield TextField::new('username')->onlyWhenUpdating()->setDisabled(true);
$availableRoles = ['User' => 'ROLE_USER', 'Admin' => 'ROLE_ADMIN', 'Test' => 'ROLE_TEST', 'SuperAdmin' => 'ROLE_SUPERADMIN']; $availableRoles = ['User' => 'ROLE_USER', 'Admin' => 'ROLE_ADMIN', 'Test' => 'ROLE_TEST', 'SuperAdmin' => 'ROLE_SUPERADMIN'];
yield ChoiceField::new ('roles') yield ChoiceField::new('roles')
->setChoices($availableRoles) ->setChoices($availableRoles)
->allowMultipleChoices(true); ->allowMultipleChoices(true);
yield FormField::addPanel('Set password')->setIcon('fa fa-key'); yield FormField::addFieldset('Set password')->setIcon('fa fa-key');
$fieldPassword = Field::new ('plainPassword', 'New password') $fieldPassword = Field::new('plainPassword', 'New password')
->hideOnIndex() ->hideOnIndex()
->setRequired(false) ->setRequired(false)
->setFormType(RepeatedType::class) ->setFormType(RepeatedType::class)
@@ -50,7 +50,7 @@ class UserCrudController extends AbstractCrudController
'error_bubbling' => true, 'error_bubbling' => true,
'invalid_message' => 'The password fields do not match.', 'invalid_message' => 'The password fields do not match.',
]); ]);
if($pageName == Crud::PAGE_NEW) { if ($pageName == Crud::PAGE_NEW) {
$fieldPassword->setRequired(true); $fieldPassword->setRequired(true);
} }
@@ -65,10 +65,10 @@ class UserCrudController extends AbstractCrudController
{ {
//Hash password on creation. //Hash password on creation.
$plaintextPassword = $entityInstance->getPlainPassword(); $plaintextPassword = $entityInstance->getPlainPassword();
$hashedPassword = $this->userPasswordHasher->hashPassword($entityInstance, $plaintextPassword); $hashedPassword = $this->userPasswordHasher->hashPassword($entityInstance, $plaintextPassword);
$entityInstance->setPassword($hashedPassword); $entityInstance->setPassword($hashedPassword);
parent::updateEntity($entityManager, $entityInstance); parent::updateEntity($entityManager, $entityInstance);
} }
@@ -79,7 +79,7 @@ class UserCrudController extends AbstractCrudController
{ {
$plaintextPassword = $entityInstance->getPlainPassword(); $plaintextPassword = $entityInstance->getPlainPassword();
if($plaintextPassword && $plaintextPassword != "") { if ($plaintextPassword && $plaintextPassword != "") {
//New password set. Hash password. //New password set. Hash password.
$hashedPassword = $this->userPasswordHasher->hashPassword($entityInstance, $plaintextPassword); $hashedPassword = $this->userPasswordHasher->hashPassword($entityInstance, $plaintextPassword);
$entityInstance->setPassword($hashedPassword); $entityInstance->setPassword($hashedPassword);
+2
View File
@@ -4,6 +4,7 @@ namespace App\Entity;
use App\Enum\UserRoleEnum; use App\Enum\UserRoleEnum;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Deprecated;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
@@ -120,6 +121,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
/** /**
* @see UserInterface * @see UserInterface
*/ */
#[Deprecated("Not used after Symfony 7.3")]
public function eraseCredentials(): void public function eraseCredentials(): void
{ {
// If you store any temporary, sensitive data on the user, clear it here // If you store any temporary, sensitive data on the user, clear it here
+1 -1
View File
@@ -1,7 +1,7 @@
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #} {# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #} {# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
{% if ea.crud.currentAction == 'detail' %} {% if ea().crud.currentAction == 'detail' %}
<div class="field-icon-div d-flex gap-3"> <div class="field-icon-div d-flex gap-3">
<span title="{{ field.value }}">{{ field.formattedValue|raw }}</span> <span title="{{ field.value }}">{{ field.formattedValue|raw }}</span>
<div class="badge text-bg-secondary"> <div class="badge text-bg-secondary">