You are here

public static function ZoneTerritory::validatePostalCodeElements in Address 8

Validates the postal code elements.

Parameters

array $element: The existing form element array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

File

src/Element/ZoneTerritory.php, line 285

Class

ZoneTerritory
Provides a zone territory form element.

Namespace

Drupal\address\Element

Code

public static function validatePostalCodeElements(array $element, FormStateInterface $form_state) {
  $value = $form_state
    ->getValue($element['#parents']);
  if (empty($value['limit_by_postal_code'])) {

    // Remove postal code values if the main checkbox was unchecked.
    unset($value['included_postal_codes']);
    unset($value['excluded_postal_codes']);
  }
  unset($value['limit_by_postal_code']);
  $form_state
    ->setValue($element['#parents'], $value);
}