You are here

public function WorkflowConfigTransitionFormBase::buildForm in Workflow 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/WorkflowConfigTransitionFormBase.php, line 147

Class

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

Namespace

Drupal\workflow\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = [];
  if (!$this->workflow) {
    return $form;
  }

  /*
   * Begin of copied code DraggableListBuilder::buildForm()
   */
  $form[$this->entitiesKey] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#sticky' => TRUE,
    '#empty' => $this
      ->t('There is no @label yet.', [
      '@label' => 'Transition',
    ]),
    '#tabledrag' => [
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'weight',
      ],
    ],
  ];
  $this->entities = $this
    ->load();
  $delta = 10;

  // Change the delta of the weight field if have more than 20 entities.
  if (!empty($this->weightKey)) {
    $count = count($this->entities);
    if ($count > 20) {
      $delta = ceil($count / 2);
    }
  }
  foreach ($this->entities as $entity) {
    $row = $this
      ->buildRow($entity);
    if (isset($row['label'])) {
      $row['label'] = [
        '#markup' => $row['label'],
      ];
    }
    if (isset($row['weight'])) {
      $row['weight']['#delta'] = $delta;
    }
    $form[$this->entitiesKey][$entity
      ->id()] = $row;
  }

  /*
   * End of copied code DraggableListBuilder::buildForm()
   */
  $form = parent::buildForm($form, $form_state);
  return $form;
}