You are here

public function MobileNumber::validateConfigurationForm in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/WebformElement/MobileNumber.php \Drupal\mobile_number\Plugin\WebformElement\MobileNumber::validateConfigurationForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides WebformElementBase::validateConfigurationForm

File

src/Plugin/WebformElement/MobileNumber.php, line 91

Class

MobileNumber
Provides a 'mobile_number' element.

Namespace

Drupal\mobile_number\Plugin\WebformElement

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::validateConfigurationForm($form, $form_state);
  $default_country = $form_state
    ->getValue('default_country');
  $allowed_countries = $form_state
    ->getValue('countries');
  if (!empty($allowed_countries) && !in_array($default_country, $allowed_countries)) {
    $form_state
      ->setErrorByName('mobile_number][default_country', t('Default country is not in one of the allowed countries.'));
  }
}