You are here

public function OrganigramsImportItemsForm::validateForm in Organigrams 8.2

Validate the JSON.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormBase::validateForm

File

src/Form/OrganigramsImportItemsForm.php, line 124

Class

OrganigramsImportItemsForm
Provides the settings form for this module.

Namespace

Drupal\organigrams\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $organigram_items = Json::decode($form_state
    ->getValue('organigrams_items_json'));
  if (empty($organigram_items)) {
    $form_state
      ->setErrorByName('organigrams_items_json', $this
      ->t('No organigram items found in the JSON.'));
  }
}