You are here

public function OrganigramsImportD7Form::validateForm in Organigrams 8.2

Same name and namespace in other branches
  1. 8 src/Form/OrganigramsImportD7Form.php \Drupal\organigrams\Form\OrganigramsImportD7Form::validateForm()

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/OrganigramsImportD7Form.php, line 70

Class

OrganigramsImportD7Form
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 = json_decode($form_state
    ->getValue('organigrams_d7_json'));
  if (empty($organigram->organigram)) {
    $form_state
      ->setErrorByName('organigrams_d7_json', $this
      ->t('No organigram found in the JSON.'));
  }
  else {
    $vocabularies = taxonomy_vocabulary_get_names();
    if (isset($vocabularies[$organigram->organigram->machine_name])) {
      $form_state
        ->setErrorByName('organigrams_d7_json', $this
        ->t('An organigram with the machine name "@machine_name" already exists. Change the machine name or remove the existing one to import this organigram.', [
        '@machine_name' => $organigram->organigram->machine_name,
      ]));
    }
  }
}