You are here

public function ImportForm::validateForm in Feed Import 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/ImportForm.php, line 65
Contains \Drupal\feed_import\Form\ImportForm

Class

ImportForm

Namespace

Drupal\feed_import\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($machine_name = $form_state
    ->getValue('machine_name')) {
    if (is_numeric($machine_name) || is_numeric($machine_name[0])) {
      $form_state
        ->setError($form['machine_name'], t('Machine name must be not numeric!'));
    }
  }
  $code = trim($form_state
    ->getValue('code'));
  if (!$code || !($code = @json_decode($code, TRUE))) {
    $form_state
      ->setError($form['code'], t('Invalid JSON code!'));
    return;
  }
  if (!is_array($code)) {
    $form_state
      ->setError($form['code'], t('Invalid feed format!'));
    return;
  }
}