You are here

protected function BulkEditFormTrait::getBundleForm in Views Bulk Edit 8.2

Gets the form for this entity display.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle ID.

mixed $bundle_label: Bundle label.

array $form: Form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form_state object.

int $bundle_count: Number of bundles that may be affected.

Return value

array Edit form for the current entity bundle.

1 call to BulkEditFormTrait::getBundleForm()
BulkEditFormTrait::buildBundleForms in src/Form/BulkEditFormTrait.php
Builds the bundle forms.

File

src/Form/BulkEditFormTrait.php, line 109

Class

BulkEditFormTrait
Common methods for Views Bulk Edit forms.

Namespace

Drupal\views_bulk_edit\Form

Code

protected function getBundleForm($entity_type_id, $bundle, $bundle_label, array $form, FormStateInterface $form_state, $bundle_count) {
  $entityType = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $entity = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->create([
    $entityType
      ->getKey('bundle') => $bundle,
  ]);
  if (!isset($form[$entity_type_id])) {
    $form[$entity_type_id] = [
      '#type' => 'container',
      '#tree' => TRUE,
    ];
  }

  // If there is no bundle label, the entity has no bundles.
  if (empty($bundle_label)) {
    $bundle_label = $entityType
      ->getLabel();
  }
  $form[$entity_type_id][$bundle] = [
    '#type' => 'details',
    '#open' => $bundle_count === 1,
    '#title' => $entityType
      ->getLabel() . ' - ' . $bundle_label,
    '#parents' => [
      $entity_type_id,
      $bundle,
    ],
  ];
  $form_display = EntityFormDisplay::collectRenderDisplay($entity, 'bulk_edit');
  $form_display
    ->buildForm($entity, $form[$entity_type_id][$bundle], $form_state);
  $form[$entity_type_id][$bundle] += $this
    ->getSelectorForm($entity_type_id, $bundle, $form[$entity_type_id][$bundle]);
  $form[$entity_type_id][$bundle] += $this
    ->getRevisionForm($entity);
  return $form;
}