You are here

public function WorkflowStateListBuilder::validateForm in Workflow 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 DraggableListBuilder::validateForm

File

src/WorkflowStateListBuilder.php, line 259

Class

WorkflowStateListBuilder
Defines a class to build a draggable listing of Workflow State entities.

Namespace

Drupal\workflow

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // @todo D8: enable WorkflowState machine_name as interactive element.
  foreach ($form_state
    ->getValue($this->entitiesKey) as $sid => $value) {

    /** @var \Drupal\workflow\Entity\WorkflowState $state */
    $state = isset($this->entities[$sid]) ? $this->entities[$sid] : NULL;

    // State is de-activated (reassigning current content).
    if ($state && $state
      ->isActive() && !$value['status']) {
      $args = [
        '%state' => $state
          ->label(),
      ];

      // Does that state have content in it?
      if (!$form['#last_mohican'] && $value['count'] > 0 && empty($value['reassign'])) {
        $message = 'The %state state has content; you must
              reassign the content to another state.';
        $form_state
          ->setErrorByName("states'][{$sid}]['reassign'", $this
          ->t($message, $args));
      }
    }
  }
}