You are here

public function FormatTextFilter::validateArguments in Typed Data API enhancements 8

Validates the inputted arguments.

Determines whether the given arguments have a valid syntax and can be applied to data of the given definition.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $definition: The definition of the filtered data.

string[] $arguments: The array of filter arguments.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] An array of translated validation error messages. If the arguments are valid, an empty array must be returned.

Overrides DataFilterBase::validateArguments

File

src/Plugin/TypedDataFilter/FormatTextFilter.php, line 45

Class

FormatTextFilter
A data filter which marks string data as sanitized.

Namespace

Drupal\typed_data\Plugin\TypedDataFilter

Code

public function validateArguments(DataDefinitionInterface $definition, array $arguments) {
  $errors = parent::validateArguments($definition, $arguments);
  if (isset($arguments[0])) {

    // Ensure the provided value is given for this data.
    $violations = $this
      ->getTypedDataManager()
      ->create($definition, $arguments[0])
      ->validate();
    foreach ($violations as $violation) {
      $errors[] = $violation
        ->getMessage();
    }
  }
  return $errors;
}