getSnippet example


    public function validate($userName, Constraint $constraint)
    {
        if (!$constraint instanceof UserName) {
            return;
        }

        $userId = $constraint->getUserId();

        if (empty($userName)) {
            $this->addError($this->getSnippet(NoUrlValidator::SNIPPET_EMPTY_FIELD));
        }

        if (!$this->userNameValidator->isValid($userName)) {
            $this->addError($this->getSnippet(self::SNIPPET_NAME_FAILURE));
        }

        if ($this->isExistingUser($userName$userId)) {
            $this->addError($this->getSnippet(self::SNIPPET_NAME_DUPLICATE));
        }
    }

    
$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'));
            $form->addError($error);
        }
    }

    /** * @return string */
    public function validatedBy()
    {
        return 'FormEmailValidator';
    }


    /** * @return Constraint[] */
    private function getBirthdayConstraints()
    {
        $constraints = [];

        if ($this->config->get('showBirthdayField') && $this->config->get('requireBirthdayField')) {
            $constraints[] = new NotBlank([
                'message' => $this->getSnippet(PersonalFormType::SNIPPET_BIRTHDAY),
            ]);
        }

        return $constraints;
    }

    /** * @param array $snippet with namespace, name and default value * * @return string */
    
/** @var Form $form */
        $form = $this->context->getRoot();

        if ($this->isFastLogin($form)) {
            return;
        }

        $minLength = (int) $this->config->get('minPassword');

        if (empty($password) || ($minLength && \strlen($password) < $minLength)) {
            $this->addError($this->getSnippet(self::SNIPPET_PASSWORD_LENGTH));
        }

        if ($form->has('passwordConfirmation') && $form->get('passwordConfirmation')->getData() !== $password) {
            $error = new FormError($this->getSnippet(self::SNIPPET_PASSWORD_CONFIRMATION));
            $error->setOrigin($form->get('passwordConfirmation'));
            $form->addError($error);
        }
    }

    private function addError(string $message): void
    {
        
public function validate($email, Constraint $constraint)
    {
        if (!$constraint instanceof CustomerEmail) {
            return;
        }

        $shop = $constraint->getShop();

        $customerId = $constraint->getCustomerId();

        if (empty($email)) {
            $this->addError($this->getSnippet(self::SNIPPET_MAIL_FAILURE));
        }

        if (!$this->emailValidator->isValid($email)) {
            $this->addError($this->getSnippet(self::SNIPPET_MAIL_FAILURE));
        }

        if (!$this->isFastLogin($constraint) && $this->isExistingEmail($email$shop$customerId)) {
            $this->addError($this->getSnippet(self::SNIPPET_MAIL_DUPLICATE));
        }
    }

    
/** * @param string $text */
    public function validate($text, Constraint $constraint): void
    {
        if (!$constraint instanceof NoUrl) {
            return;
        }

        if (empty($text)) {
            $this->addError($this->getSnippet(self::SNIPPET_EMPTY_FIELD));
        }

        if (!$this->noUrlValidator->isValid($text)) {
            $this->addError($this->getSnippet(PersonalFormType::SNIPPET_URL));
        }
    }

    private function addError(string $message): void
    {
        $this->context
            ->buildViolation($message)
            
$builder->add('salutation', SalutationType::class[
                'constraints' => [new NotBlank(['message' => null])],
            ]);
        }

        $builder->add('title', TextType::class);

        $builder->add('firstname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
                'message' => $this->getSnippet(self::SNIPPET_URL),
            ])],
        ]);

        $builder->add('lastname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
                'message' => $this->getSnippet(self::SNIPPET_URL),
            ])],
        ]);

        

            $_block_force = (bool) preg_match('#[\s]force#', $_block_args);
            $_block_json = (bool) preg_match('#[\s]json=["\']true["\']\W#', $_block_args);
            $_block_name = !empty($_match[3]) ? trim($_match[3], '\'"') : $_block_default;
            if (preg_match("!(.?)(namespace=)(.*?)(?=(\s|$))!", $_block_args$_match)) {
                $_namespace = trim($_match[3], '\'"');
            } else {
                $_namespace = $_block_namespace;
            }
            $_block_args = str_replace('"', '\'', $_block_args);

            $_block_content = $this->getSnippet($_namespace$_block_name$_block_default$_block_force);

            if ($_block_json) {
                $_block_content = json_encode($_block_content);
            }

            if (!empty($_block_default)) {
                $_block_args .= ' default=' . var_export($_block_default, true);
            }
            if (!empty($_block_namespace)) {
                $_block_args .= ' namespace=' . var_export($_block_namespace, true);
            }
            

    public function validate($email, Constraint $constraint)
    {
        if (!$constraint instanceof UserEmail) {
            return;
        }

        $userId = $constraint->getUserId();

        if (empty($email)) {
            $this->addError($this->getSnippet(NoUrlValidator::SNIPPET_EMPTY_FIELD));
        }

        if (!$this->emailValidator->isValid($email)) {
            $this->addError($this->getSnippet(self::SNIPPET_MAIL_FAILURE));
        }

        if ($this->isExistingEmail($email$userId)) {
            $this->addError($this->getSnippet(self::SNIPPET_MAIL_DUPLICATE));
        }
    }

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