CustomerEmail example

if (!$constraint instanceof FormEmail) {
            return;
        }

        /** @var FormInterface<Customer> $form */
        $form = $this->context->getRoot();

        $customer = $form->getData();

        $accountMode = $this->getAccountMode($form);

        $emailConstraint = new CustomerEmail([
            'shop' => $constraint->getShop(),
            'customerId' => $customer->getId(),
            'accountMode' => $accountMode,
        ]);

        $this->customerEmailValidator->initialize($this->context);
        $this->customerEmailValidator->validate($email$emailConstraint);

        if ($form->has('emailConfirmation') && $form->get('emailConfirmation')->getData() !== $email) {
            $error = new FormError($this->getSnippet());
            $error->setOrigin($form->get('emailConfirmation'));
            
$this->validationContext = $this->validator->startContext();

        $this->validateField('firstname', $customer->getFirstname()[new NotBlank()]);
        $this->validateField('lastname', $customer->getLastname()[new NotBlank()]);

        $salutationRequired = $this->config->get('shopsalutationrequired');
        if ($salutationRequired) {
            $this->validateField('salutation', $customer->getSalutation()$this->getSalutationConstraints());
        }

        $this->validateField('email', $customer->getEmail()[
            new CustomerEmail([
                'shop' => $this->context->getShopContext()->getShop(),
                'customerId' => $customer->getId(),
                'accountMode' => $customer->getAccountMode(),
            ]),
        ]);

        if ($this->validationContext->getViolations()->count() > 0) {
            throw new ValidationException($this->validationContext->getViolations());
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.