You are here

protected function AbstractPatternsDeriver::isValidPatternDefinition in UI Patterns 8

Validate pattern definition.

Parameters

\Drupal\ui_patterns\Definition\PatternDefinition $definition: Pattern definition.

Return value

bool Whereas current pattern definition is valid or not.

1 call to AbstractPatternsDeriver::isValidPatternDefinition()
AbstractPatternsDeriver::getDerivativeDefinitions in src/Plugin/Deriver/AbstractPatternsDeriver.php
Gets the definition of all derivatives of a base plugin.

File

src/Plugin/Deriver/AbstractPatternsDeriver.php, line 93

Class

AbstractPatternsDeriver
Class AbstractPatternsDeriver.

Namespace

Drupal\ui_patterns\Plugin\Deriver

Code

protected function isValidPatternDefinition(PatternDefinition $definition) {
  $data_definition = PatternDataDefinition::create();
  $violations = $this->typedDataManager
    ->create($data_definition, $definition
    ->toArray())
    ->validate();
  if ($violations
    ->count()) {

    /** @var \Symfony\Component\Validator\ConstraintViolation $violation */
    $this->messenger
      ->addError($this
      ->t("Pattern ':id' is skipped because of the following validation error(s):", [
      ':id' => $definition
        ->id(),
    ]));
    foreach ($violations as $violation) {
      $message = $this
        ->t('Validation error on ":id.:property": :message', [
        ':id' => $definition
          ->id(),
        ':property' => $violation
          ->getPropertyPath(),
        ':message' => $violation
          ->getMessage(),
      ]);
      $this->messenger
        ->addError($message);
    }
    return FALSE;
  }
  return TRUE;
}