You are here

public function NodeOrderListBuilder::buildForm in Node Order 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 FormInterface::buildForm

File

src/NodeOrderListBuilder.php, line 210

Class

NodeOrderListBuilder
Defines a class to build a listing of node entities.

Namespace

Drupal\nodeorder

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#title'] = $this
    ->t('Order nodes for <em>%term_name</em>', [
    '%term_name' => $this->taxonomyTerm
      ->label(),
  ]);
  $form['term_id'] = [
    '#type' => 'value',
    '#value' => $this->taxonomyTerm
      ->id(),
  ];
  $form[$this->entitiesKey] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#empty' => $this
      ->t('There is no @label yet.', [
      '@label' => $this->entityType
        ->getLabel(),
    ]),
    '#tabledrag' => [
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'weight',
      ],
    ],
  ];
  $this->entities = $this
    ->load();
  $weight_delta = ceil($this->entitiesCount / 2);
  foreach ($this->entities as $entity) {
    if ($row = $this
      ->buildRow($entity, $weight_delta)) {
      $form[$this->entitiesKey][$entity
        ->id()] = $row;
    }
  }
  if ($this->limit) {
    $form['pager'] = [
      '#type' => 'pager',
    ];
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
  ];
  return $form;
}