public function BulkEditForm::submitForm in Views Bulk Edit 8
Same name and namespace in other branches
- 8.2 src/Form/BulkEditForm.php \Drupal\views_bulk_edit\Form\BulkEditForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ BulkEditForm.php, line 185
Class
- BulkEditForm
- The bulk edit form.
Namespace
Drupal\views_bulk_edit\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$entities_by_bundle = $this
->getEntitiesByBundle();
$count = 0;
$form_state
->cleanValues();
foreach ($entities_by_bundle as $bundle => $entities) {
$update_values = array_filter($form_state
->getValue([
$bundle,
'field_selector',
]));
$count += count($entities);
foreach ($entities as $entity) {
$form['#parents'] = [
$bundle,
];
$form_state
->setValue($bundle, $this
->filterOnKey($form_state
->getValue($bundle), function ($key) use ($update_values) {
return !empty($update_values[$key]);
}));
$form_state
->get('form_display')
->extractFormValues($entity, $form, $form_state);
$entity
->save();
}
}
drupal_set_message(t('Updated @count entities', [
'@count' => $count,
]));
$this
->clearBulkEditEntityData();
}