You are here

public static function RgElement::validateElement in Brazilian IDs 8

Validates the RG element.

File

src/Element/RgElement.php, line 124

Class

RgElement
Plugin annotation @FormElement("brazilian_ids_rg");

Namespace

Drupal\brazilian_ids\Element

Code

public static function validateElement(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = $element['#value'];

  // If any of the properties are provided, then all of them must be.
  $filled_properties = array_filter($value);
  $empty_properties = array_diff_key($value, $filled_properties);
  if ($filled_properties && $empty_properties) {
    foreach ($empty_properties as $property => $value) {
      $property_element =& $element['rg_fields'][$property];
      $form_state
        ->setError($property_element, t('The @field\'s %property must be provided.', [
        '@field' => $element['#title'],
        '%property' => $property_element['#title'],
      ]));
    }
  }
}