You are here

public function ConvertNodesForm::validateForm in Convert Nodes 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/ConvertNodesForm.php, line 340

Class

ConvertNodesForm
ConvertNodesForm.

Namespace

Drupal\convert_nodes\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  switch ($this->step) {
    case 1:
      $this->from_type = $form['convert_nodes_content_type_from']['#value'];
      $this->to_type = $form['convert_nodes_content_type_to']['#value'];
      $query = $this->entityTypeManager
        ->getStorage('node')
        ->getQuery()
        ->condition('type', $this->from_type);
      $count_type = $query
        ->count()
        ->execute();
      if ($count_type == 0) {
        $form_state
          ->setErrorByName('convert_nodes_content_type_from', $this
          ->t('No content found to convert.'));
      }
      elseif ($this->from_type == $this->to_type) {
        $form_state
          ->setErrorByName('convert_nodes_content_type_to', $this
          ->t('Please select different content types.'));
      }
      break;
    default:

      // TODO - validate other steps.
      break;
  }
}