You are here

public function MultipleNidsExportForm::validateForm in Node export 8

Form validation handler.

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/MultipleNidsExportForm.php, line 43

Class

MultipleNidsExportForm
Provides a Multiple Node Export form using Nids.

Namespace

Drupal\node_Export\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $nids = $form_state
    ->getValue('nids');
  $array = explode("\n", $nids);
  foreach ($array as $nid) {
    $nid = trim($nid);
    if (!filter_var($nid, FILTER_VALIDATE_INT)) {
      $form_state
        ->setErrorByName('NIDS', $this
        ->t('Please enter valid list of Node Ids. "@node_id" is not in right format', [
        '@node_id' => $nid,
      ]));
    }
  }
  if (count($array) != count(array_unique($array))) {
    $form_state
      ->setErrorByName('NIDS', $this
      ->t('You have entered same Node IDs.'));
  }
}