public function ConfigureAction::buildForm in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.3 src/Form/ConfigureAction.php \Drupal\views_bulk_operations\Form\ConfigureAction::buildForm()
- 8.2 src/Form/ConfigureAction.php \Drupal\views_bulk_operations\Form\ConfigureAction::buildForm()
- 4.0.x src/Form/ConfigureAction.php \Drupal\views_bulk_operations\Form\ConfigureAction::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/ ConfigureAction.php, line 81
Class
- ConfigureAction
- Action configuration form.
Namespace
Drupal\views_bulk_operations\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $view_id = NULL, $display_id = NULL) {
$form_data = $this
->getFormData($view_id, $display_id);
// TODO: display an error msg, redirect back.
if (!isset($form_data['action_id'])) {
return;
}
$form['#title'] = $this
->t('Configure "%action" action applied to the selection', [
'%action' => $form_data['action_label'],
]);
$selection = [];
if (!empty($form_data['entity_labels'])) {
$form['list'] = [
'#theme' => 'item_list',
'#items' => $form_data['entity_labels'],
];
}
else {
$form['list'] = [
'#type' => 'item',
'#markup' => $this
->t('All view results'),
];
}
$form['list']['#title'] = $this
->t('Selected @count entities:', [
'@count' => $form_data['selected_count'],
]);
// :D Make sure the submit button is at the bottom of the form
// and is editale from the action buildConfigurationForm method.
$form['actions']['#weight'] = 666;
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Apply'),
'#submit' => [
[
$this,
'submitForm',
],
],
];
$action = $this->actionManager
->createInstance($form_data['action_id']);
if (method_exists($action, 'setContext')) {
$action
->setContext($form_data);
}
$form = $action
->buildConfigurationForm($form, $form_state);
$storage = $form_state
->getStorage();
$storage['views_bulk_operations'] = $form_data;
$form_state
->setStorage($storage);
return $form;
}