You are here

public function WorkflowConfigTransitionLabelForm::buildRow in Workflow 8

File

src/Form/WorkflowConfigTransitionLabelForm.php, line 42

Class

WorkflowConfigTransitionLabelForm
Defines a class to build a draggable listing of Workflow Config Transitions entities.

Namespace

Drupal\workflow\Form

Code

public function buildRow(EntityInterface $entity) {
  $row = [];
  $workflow = $this->workflow;
  if ($workflow) {

    /** @var \Drupal\workflow\Entity\WorkflowConfigTransition $entity */
    $config_transition = $entity;
    static $previous_from_sid = -1;

    // Get transitions, sorted by weight of the old state.
    $from_state = $config_transition
      ->getFromState();
    $to_state = $config_transition
      ->getToState();
    $from_sid = $from_state
      ->id();

    // Skip the transitions without any roles.
    $skip = TRUE;
    foreach ($config_transition->roles as $rid => $active) {
      if ($active) {
        $skip = FALSE;
      }
    }
    if ($skip == TRUE && $from_state != $to_state) {
      return $row;
    }
    $row['from'] = [
      '#type' => 'value',
      '#markup' => $previous_from_sid != $from_sid ? $from_state
        ->label() : '"',
    ];
    $row['to'] = [
      '#type' => 'value',
      '#markup' => $to_state
        ->label(),
    ];
    $row['label_new'] = [
      '#type' => 'textfield',
      '#default_value' => $config_transition
        ->get('label'),
    ];
    $row['config_transition'] = [
      '#type' => 'value',
      '#value' => $config_transition,
    ];
    $previous_from_sid = $from_sid;
  }
  return $row;
}