You are here

public function YamlFormEntityElementsValidator::validate in YAML Form 8

Validate form elements.

Parameters

\Drupal\yamlform\YamlFormInterface $yamlform: A form.

Return value

array|null An array of error messages or NULL is the elements are valid.

File

src/YamlFormEntityElementsValidator.php, line 64

Class

YamlFormEntityElementsValidator
Defines a class to validate form elements.

Namespace

Drupal\yamlform

Code

public function validate(YamlFormInterface $yamlform) {
  $this->yamlform = $yamlform;
  $this->elementsRaw = $yamlform
    ->getElementsRaw();
  $this->originalElementsRaw = $yamlform
    ->getElementsOriginalRaw();

  // Validate required.
  if ($message = $this
    ->validateRequired()) {
    return [
      $message,
    ];
  }

  // Validate contain valid YAML.
  if ($message = $this
    ->validateYaml()) {
    return [
      $message,
    ];
  }
  $this->elements = Yaml::decode($this->elementsRaw);
  $this->originalElements = Yaml::decode($this->originalElementsRaw);

  // Validate elements are an array.
  if ($message = $this
    ->validateArray()) {
    return [
      $message,
    ];
  }

  // Validate duplicate element name.
  if ($messages = $this
    ->validateDuplicateNames()) {
    return $messages;
  }

  // Validate ignored properties.
  if ($messages = $this
    ->validateProperties()) {
    return $messages;
  }

  // Validate submission data.
  if ($messages = $this
    ->validateSubmissions()) {
    return $messages;
  }

  // Validate hierarchy.
  if ($messages = $this
    ->validateHierarchy()) {
    return $messages;
  }

  // Validate rendering.
  if ($message = $this
    ->validateRendering()) {
    return [
      $message,
    ];
  }
  return NULL;
}