You are here

protected function WebformAdminConfigBaseForm::buildBulkOperations in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/AdminConfig/WebformAdminConfigBaseForm.php \Drupal\webform\Form\AdminConfig\WebformAdminConfigBaseForm::buildBulkOperations()

Build bulk operation settings for webforms and submissions.

Parameters

array $settings: Webform settings.

$entity_type_id: The entity type id. (webform or webform_submission)

Return value

array

2 calls to WebformAdminConfigBaseForm::buildBulkOperations()
WebformAdminConfigFormsForm::buildForm in src/Form/AdminConfig/WebformAdminConfigFormsForm.php
Form constructor.
WebformAdminConfigSubmissionsForm::buildForm in src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php
Form constructor.

File

src/Form/AdminConfig/WebformAdminConfigBaseForm.php, line 47

Class

WebformAdminConfigBaseForm
Base webform admin settings form.

Namespace

Drupal\webform\Form\AdminConfig

Code

protected function buildBulkOperations(array $settings, $entity_type_id) {
  $element = [
    '#type' => 'details',
    '#title' => $entity_type_id === 'webform_submission' ? $this
      ->t('Submissions bulk operations settings') : $this
      ->t('Form bulk operations settings'),
    '#open' => TRUE,
    '#tree' => TRUE,
  ];

  // Enable.
  $settings += [
    $entity_type_id . '_bulk_form' => TRUE,
  ];
  $element[$entity_type_id . '_bulk_form'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enabled webform bulk operations'),
    '#description' => $entity_type_id === 'webform_submission' ? $this
      ->t('If checked, bulk operations will be displayed on the submission results page.') : $this
      ->t('If checked, bulk operations will be displayed on the form manager page.'),
    '#return_value' => TRUE,
    '#default_value' => $settings[$entity_type_id . '_bulk_form'],
  ];

  // Actions.
  $options = [];
  $default_actions = [];

  /** @var \Drupal\system\ActionConfigEntityInterface[] $actions */
  $actions = \Drupal::entityTypeManager()
    ->getStorage('action')
    ->loadMultiple();
  foreach ($actions as $action) {
    if ($action
      ->getType() === $entity_type_id) {
      $options[$action
        ->id()] = [
        'label' => $action
          ->label(),
      ];
      $default_actions[] = $action
        ->id();
    }
  }
  $settings += [
    $entity_type_id . '_bulk_form_actions' => $default_actions,
  ];
  $element[$entity_type_id . '_bulk_form_actions'] = [
    '#type' => 'webform_tableselect_sort',
    '#title' => $entity_type_id === 'webform_submission' ? $this
      ->t('Submissions selected actions') : $this
      ->t('Form selected actions'),
    '#header' => [
      'label' => $this
        ->t('Selected actions'),
    ],
    '#options' => $options,
    '#default_value' => array_combine($settings[$entity_type_id . '_bulk_form_actions'], $settings[$entity_type_id . '_bulk_form_actions']),
    '#states' => [
      'visible' => [
        ':input[name="bulk_form_settings[' . $entity_type_id . '_bulk_form]"]' => [
          'checked' => TRUE,
        ],
      ],
      'required' => [
        ':input[name="bulk_form_settings[' . $entity_type_id . '_bulk_form]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
    '#element_validate' => [
      [
        get_class($this),
        'validateBulkFormActions',
      ],
    ],
  ];
  WebformElementHelper::fixStatesWrapper($element[$entity_type_id . '_bulk_form_actions']);
  return $element;
}