You are here

public function BulkEditForm::buildForm in Views Bulk Edit 8

Same name and namespace in other branches
  1. 8.2 src/Form/BulkEditForm.php \Drupal\views_bulk_edit\Form\BulkEditForm::buildForm()

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/Form/BulkEditForm.php, line 60

Class

BulkEditForm
The bulk edit form.

Namespace

Drupal\views_bulk_edit\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  if (!$this
    ->getBulkEditEntityData()) {
    $form['direct_access']['#markup'] = $this
      ->t('You must use a valid bulk operations form to first select the entities to change');
    return $form;
  }
  $form['#attributes']['class'] = [
    'bulk-edit-form',
  ];
  $form["#attached"]['library'][] = 'views_bulk_edit/views_bulk_edit.edit_form';
  $form['#tree'] = TRUE;
  $form['selector'] = [
    '#type' => 'container',
    '#tree' => TRUE,
  ];
  foreach ($this
    ->getBulkEditEntityData() as $entity_type_id => $bundle_entities) {
    foreach ($bundle_entities as $bundle => $entities) {
      $form = $this
        ->getForm($entity_type_id, $bundle, $form, $form_state);
    }
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#submit' => [
      '::submitForm',
    ],
    '#button_type' => 'primary',
  ];
  return $form;
}