You are here

public function MobileNumberWidget::settingsFormValidate in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldWidget/MobileNumberWidget.php \Drupal\mobile_number\Plugin\Field\FieldWidget\MobileNumberWidget::settingsFormValidate()

Form element validation handler.

Parameters

array $element: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

File

src/Plugin/Field/FieldWidget/MobileNumberWidget.php, line 108

Class

MobileNumberWidget
Plugin implementation of the 'mobile_number' widget.

Namespace

Drupal\mobile_number\Plugin\Field\FieldWidget

Code

public function settingsFormValidate(array $element, FormStateInterface $form_state) {
  $parents = $element['#parents'];
  array_pop($parents);
  $settings = $this
    ->getFieldSettings();
  $settings += NestedArray::getValue($form_state
    ->getValues(), $parents);
  $default_country = $settings['default_country'];
  $allowed_countries = $settings['countries'];
  if (!empty($allowed_countries) && !in_array($default_country, $allowed_countries)) {
    $form_state
      ->setError($element, t('Default country is not in one of the allowed countries.'));
  }
}