public function DeleteMultiple::submitForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Form/DeleteMultiple.php \Drupal\node\Form\DeleteMultiple::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
- core/
modules/ node/ src/ Form/ DeleteMultiple.php, line 150 - Contains \Drupal\node\Form\DeleteMultiple.
Class
- DeleteMultiple
- Provides a node deletion confirmation form.
Namespace
Drupal\node\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('confirm') && !empty($this->nodeInfo)) {
$total_count = 0;
$delete_nodes = [];
/** @var \Drupal\Core\Entity\ContentEntityInterface[][] $delete_translations */
$delete_translations = [];
/** @var \Drupal\node\NodeInterface[] $nodes */
$nodes = $this->storage
->loadMultiple(array_keys($this->nodeInfo));
foreach ($this->nodeInfo as $id => $langcodes) {
foreach ($langcodes as $langcode) {
$node = $nodes[$id]
->getTranslation($langcode);
if ($node
->isDefaultTranslation()) {
$delete_nodes[$id] = $node;
unset($delete_translations[$id]);
$total_count += count($node
->getTranslationLanguages());
}
elseif (!isset($delete_nodes[$id])) {
$delete_translations[$id][] = $node;
}
}
}
if ($delete_nodes) {
$this->storage
->delete($delete_nodes);
$this
->logger('content')
->notice('Deleted @count posts.', array(
'@count' => count($delete_nodes),
));
}
if ($delete_translations) {
$count = 0;
foreach ($delete_translations as $id => $translations) {
$node = $nodes[$id]
->getUntranslated();
foreach ($translations as $translation) {
$node
->removeTranslation($translation
->language()
->getId());
}
$node
->save();
$count += count($translations);
}
if ($count) {
$total_count += $count;
$this
->logger('content')
->notice('Deleted @count content translations.', array(
'@count' => $count,
));
}
}
if ($total_count) {
drupal_set_message($this
->formatPlural($total_count, 'Deleted 1 post.', 'Deleted @count posts.'));
}
$this->tempStoreFactory
->get('node_multiple_delete_confirm')
->delete(\Drupal::currentUser()
->id());
}
$form_state
->setRedirect('system.admin_content');
}