getMessageTemplate example

$builder->disableTranslation();
        $builder->addViolation();
    }

    private function assertViolationEquals(ConstraintViolation $expectedViolation)
    {
        $this->assertCount(1, $this->violations);

        $violation = $this->violations->get(0);

        $this->assertSame($expectedViolation->getMessage()$violation->getMessage());
        $this->assertSame($expectedViolation->getMessageTemplate()$violation->getMessageTemplate());
        $this->assertSame($expectedViolation->getParameters()$violation->getParameters());
        $this->assertSame($expectedViolation->getPlural()$violation->getPlural());
        $this->assertSame($expectedViolation->getRoot()$violation->getRoot());
        $this->assertSame($expectedViolation->getPropertyPath()$violation->getPropertyPath());
        $this->assertSame($expectedViolation->getInvalidValue()$violation->getInvalidValue());
        $this->assertSame($expectedViolation->getCode()$violation->getCode());
        $this->assertEquals($expectedViolation->getConstraint()$violation->getConstraint());
        $this->assertSame($expectedViolation->getCause()$violation->getCause());
    }
}
$violations = [];

        foreach ($errors as $error) {
            if (!$error instanceof FormError) {
                continue;
            }
            $message = Shopware()->Template()->fetch('string:' . $error->getMessage());

            $origin = $error->getOrigin();
            $violations[] = new ConstraintViolation(
                $message,
                $error->getMessageTemplate(),
                $error->getMessageParameters(),
                $origin ? $origin->getRoot() : null,
                $origin ? (string) $origin->getPropertyPath() : null,
                $origin ? $origin->getData() : null,
                $error->getMessagePluralization(),
                null,
                null,
                $error->getCause()
            );
        }

        
public function testRetrievedMessageTemplateIsAStringEvenIfNotSet()
    {
        self::assertSame(
            '',
            (new ConstraintViolation(
                'irrelevant',
                null,
                [],
                'irrelevant',
                'irrelevant',
                null
            ))->getMessageTemplate()
        );
    }
}
$payloadFieldsToSerialize = array_flip($payloadFieldsToSerialize);
        }

        $violations = [];
        $messages = [];
        foreach ($object as $violation) {
            $propertyPath = $this->nameConverter ? $this->nameConverter->normalize($violation->getPropertyPath(), null, $format$context) : $violation->getPropertyPath();

            $violationEntry = [
                'propertyPath' => $propertyPath,
                'title' => $violation->getMessage(),
                'template' => $violation->getMessageTemplate(),
                'parameters' => $violation->getParameters(),
            ];
            if (null !== $code = $violation->getCode()) {
                $violationEntry['type'] = sprintf('urn:uuid:%s', $code);
            }

            $constraint = $violation->getConstraint();
            if (
                [] !== $payloadFieldsToSerialize
                && $constraint
                && $constraint->payload
                
$constraintViolations = new ConstraintViolationList();

        foreach ($definition->getProperties() as $propertyName => $constraints) {
            $value = $data[$propertyName] ?? null;
            $violations = $this->validator->validate($value$constraints);

            /** @var ConstraintViolation $violation */
            foreach ($violations as $violation) {
                $constraintViolations->add(
                    new ConstraintViolation(
                        $violation->getMessage(),
                        $violation->getMessageTemplate(),
                        $violation->getParameters(),
                        $violation->getRoot(),
                        $path . '/' . $propertyName,
                        $violation->getInvalidValue(),
                        $violation->getPlural(),
                        $violation->getCode(),
                        $violation->getConstraint(),
                        $violation->getCause()
                    )
                );
            }
        }
$constraint = new Callback([
            'callback' => $callback,
            'groups' => 'Group',
        ]);

        $violations = $this->validate('Bernhard', $constraint, 'Group');

        /* @var ConstraintViolationInterface[] $violations */
        $this->assertCount(1, $violations);
        $this->assertSame('Message value', $violations[0]->getMessage());
        $this->assertSame('Message %param%', $violations[0]->getMessageTemplate());
        $this->assertSame(['%param%' => 'value']$violations[0]->getParameters());
        $this->assertSame('', $violations[0]->getPropertyPath());
        $this->assertSame('Bernhard', $violations[0]->getRoot());
        $this->assertSame('Bernhard', $violations[0]->getInvalidValue());
        $this->assertNull($violations[0]->getPlural());
        $this->assertNull($violations[0]->getCode());
    }

    public function testClassConstraint()
    {
        $entity = new Entity();

        
'format' => NULL,
        'editor' => 'ckeditor5',
      ]);
      $submitted_filter_format = CKEditor5::getSubmittedFilterFormat($form_state);
      $fundamental_incompatibilities = CKEditor5::validatePair($minimal_ckeditor5_editor$submitted_filter_format, FALSE);

      foreach ($fundamental_incompatibilities as $violation) {
        // If the violation uses the nonAllowedElementsMessage template, it can         // be skipped because this is a violation that automatically fixed         // within SmartDefaultSettings, but SmartDefaultSettings does not         // execute until this validator passes.         if ($violation->getMessageTemplate() === $violation->getConstraint()->nonAllowedElementsMessage) {
          continue;
        }

        // @codingStandardsIgnoreLine         $form_state->setErrorByName('editor][editor', t($violation->getMessageTemplate()$violation->getParameters()));
      }
    }
  }

  /** * Value callback to set the CKEditor 5-generated "allowed_html" value. * * Used to set the value of filter_html's "allowed_html" form item if the form * has been validated and hence `ckeditor5_validated_pair` is available * in form state. This allows setting a guaranteed to be valid value. * * `ckeditor5_validated_pair` can be set from two places: * - When switching to CKEditor 5, this is populated by * CKEditor5::buildConfigurationForm(). * - When making filter or editor settings changes, it is populated by * CKEditor5::validateConfigurationForm(). * * @param array $element * An associative array containing the properties of the element. * @param mixed $input * The incoming input to populate the form element. If this is FALSE, * the element's default value should be returned. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return string * The value to assign to the element. */
$validator->validate([
                'email' => $email,
            ]$validation);

            static::fail('No exception is thrown');
        } catch (\Throwable $exception) {
            static::assertInstanceOf(ConstraintViolationException::class$exception);
            $violations = $exception->getViolations();
            $violation = $violations->get(1);

            static::assertNotEmpty($violation);
            static::assertEquals($constraint->message, $violation->getMessageTemplate());
        }
    }

    public function testSameCustomerEmailWithExistedNonBoundAccount(): void
    {
        $email = 'john.doe@example.com';

        $salesChannelContext1 = $this->createSalesChannelContext();
        $this->createCustomerOfSalesChannel($salesChannelContext1->getSalesChannel()->getId()$email);

        $constraint = new CustomerEmailUnique([
            
$payloadFieldsToSerialize = array_flip($payloadFieldsToSerialize);
        }

        $violations = [];
        $messages = [];
        foreach ($object as $violation) {
            $propertyPath = $this->nameConverter ? $this->nameConverter->normalize($violation->getPropertyPath(), null, $format$context) : $violation->getPropertyPath();

            $violationEntry = [
                'propertyPath' => $propertyPath,
                'title' => $violation->getMessage(),
                'template' => $violation->getMessageTemplate(),
                'parameters' => $violation->getParameters(),
            ];
            if (null !== $code = $violation->getCode()) {
                $violationEntry['type'] = sprintf('urn:uuid:%s', $code);
            }

            $constraint = $violation->getConstraint();
            if (
                [] !== $payloadFieldsToSerialize
                && $constraint
                && $constraint->payload
                
/** * {@inheritdoc} */
  public function getMessage(): string|\Stringable {
    return $this->violation->getMessage();
  }

  /** * {@inheritdoc} */
  public function getMessageTemplate(): string {
    return $this->violation->getMessageTemplate();
  }

  /** * {@inheritdoc} */
  public function getParameters(): array {
    return $this->violation->getParameters();
  }

  /** * {@inheritdoc} */
                if ($violation->getPropertyPath()) {
                    $property = str_replace('][', '/', $violation->getPropertyPath());
                    $property = trim($property, '][');
                    $fieldName .= '/' . $property;
                }

                $fieldName = '/' . $fieldName;

                $violationList->add(
                    new ConstraintViolation(
                        $violation->getMessage(),
                        $violation->getMessageTemplate(),
                        $violation->getParameters(),
                        $violation->getRoot(),
                        $fieldName,
                        $violation->getInvalidValue(),
                        $violation->getPlural(),
                        $violation->getCode(),
                        $violation->getConstraint(),
                        $violation->getCause()
                    )
                );
            }
        }
$parameters = [];
      $plural = NULL;
      if ($violation instanceof ConstraintViolation) {
        $constraint = $violation->getConstraint();
        $cause = $violation->getCause();
        $parameters = $violation->getParameters();
        $plural = $violation->getPlural();
      }

      $new_violation = new ConstraintViolation(
        $violation->getMessage(),
        $violation->getMessageTemplate(),
        $parameters,
        $violation->getRoot(),
        $new_path,
        $violation->getInvalidValue(),
        $plural,
        $violation->getCode(),
        $constraint,
        $cause
      );
      $new_violations->add($new_violation);
    }
    

        return $this->path;
    }

    public function toArray(): array
    {
        $result = [];

        foreach ($this->constraintViolationList as $violation) {
            $result[] = [
                'message' => $violation->getMessage(),
                'messageTemplate' => $violation->getMessageTemplate(),
                'parameters' => $violation->getParameters(),
                'propertyPath' => $violation->getPropertyPath(),
            ];
        }

        return $result;
    }

    public function getErrors(bool $withTrace = false): \Generator
    {
        foreach ($this->getViolations() as $violation) {
            
$validator = $this->getContainer()->get(DataValidator::class);

        try {
            $validator->validate(['vatIds' => $vatIds]$validation);
        } catch (\Throwable $exception) {
            static::assertInstanceOf(ConstraintViolationException::class$exception);
            $violations = $exception->getViolations();
            $violation = $violations->get(1);

            static::assertNotEmpty($violation);
            static::assertEquals($constraint->message, $violation->getMessageTemplate());
        }
    }
}

  public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) {
    /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
    foreach ($violations as $offset => $violation) {
      $parameters = $violation->getParameters();
      if (isset($parameters['@uri'])) {
        $parameters['@uri'] = static::getUriAsDisplayableString($parameters['@uri']);
        $violations->set($offsetnew ConstraintViolation(
          $this->t($violation->getMessageTemplate()$parameters),
          $violation->getMessageTemplate(),
          $parameters,
          $violation->getRoot(),
          $violation->getPropertyPath(),
          $violation->getInvalidValue(),
          $violation->getPlural(),
          $violation->getCode()
        ));
      }
    }
    parent::flagErrors($items$violations$form$form_state);
  }
Home | Imprint | This part of the site doesn't use cookies.