Skip to content

Commit

Permalink
FRW-9524 Adjusted BO edit customer form. (#11240)
Browse files Browse the repository at this point in the history
FRW-9524 Adjusted BO edit customer form.
  • Loading branch information
dimitriyTsemma authored Dec 23, 2024
1 parent e9127b7 commit 07e30cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Spryker/Zed/Customer/Communication/Form/CustomerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,11 @@ protected function addDateOfBirthField(FormBuilderInterface $builder)
}

/**
* @param string|null $currentEmail
*
* @return list<\Symfony\Component\Validator\Constraint>
*/
protected function createEmailConstraints(): array
protected function createEmailConstraints(?string $currentEmail = null): array
{
$emailConstraints = [
new NotBlank(),
Expand All @@ -403,7 +405,11 @@ protected function createEmailConstraints(): array
$customerQuery = $this->getQueryContainer()->queryCustomers();

$emailConstraints[] = new Callback([
'callback' => function ($email, ExecutionContextInterface $context) use ($customerQuery) {
'callback' => function ($email, ExecutionContextInterface $context) use ($customerQuery, $currentEmail) {
if ($currentEmail !== null && $email === $currentEmail) {
return;
}

if ($customerQuery->findByEmail($email)->count() > 0) {
$context->addViolation('Email is already used');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ protected function addStoreField(FormBuilderInterface $builder, array $choices)
*/
protected function addEmailField(FormBuilderInterface $builder)
{
$currentEmail = $builder->getData()[static::FIELD_EMAIL] ?? null;
$builder->add(static::FIELD_EMAIL, EmailType::class, [
'label' => 'Email',
'constraints' => $this->createEmailConstraints(),
'disabled' => 'disabled',
'constraints' => $this->createEmailConstraints($currentEmail),
]);

return $this;
Expand Down

0 comments on commit 07e30cf

Please sign in to comment.