You are here

protected function BulkEditForm::getSelectorForm in Views Bulk Edit 8

Builds the selector form.

Given an entity form, create a selector form to provide options to update values.

Parameters

string $bundle: The bundle machine name.

array $form: The form we're building the selection options for.

Return value

array The new selector form.

1 call to BulkEditForm::getSelectorForm()
BulkEditForm::getForm in src/Form/BulkEditForm.php
Gets the form for this entity display.

File

src/Form/BulkEditForm.php, line 128

Class

BulkEditForm
The bulk edit form.

Namespace

Drupal\views_bulk_edit\Form

Code

protected function getSelectorForm($bundle, array &$form) {
  $selector['field_selector'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Select fields to change'),
    '#weight' => -50,
    '#tree' => TRUE,
  ];
  foreach (Element::children($form) as $key) {
    if ($key == 'field_selector' || !($element =& $this
      ->findFormElement($form[$key]))) {
      continue;
    }
    $element['#required'] = FALSE;
    $element['#tree'] = TRUE;

    // Add the toggle field to the form.
    $selector['field_selector'][$key] = [
      '#type' => 'checkbox',
      '#title' => $element['#title'],
      '#tree' => TRUE,
    ];

    // Force the original value to be hidden unless the checkbox is enabled.
    $form[$key]['#states'] = [
      'visible' => [
        sprintf('[name="%s[field_selector][%s]"]', $bundle, $key) => [
          'checked' => TRUE,
        ],
      ],
    ];
  }
  return $selector;
}