You are here

public function MenuDeleteItem::submitForm in Menu Delete 8

Same name and namespace in other branches
  1. 8.2 src/Form/MenuDeleteItem.php \Drupal\menu_delete\Form\MenuDeleteItem::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/MenuDeleteItem.php, line 128

Class

MenuDeleteItem
Class MenuDeleteItem.

Namespace

Drupal\menu_delete\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('confirm') && !empty($this->menuItems)) {
    $total_count = 0;
    foreach ($this->menuItems as $id => $item) {
      list($entity_type_id, $uuid) = explode(':', $item['id']);
      $link = $this->entityManager
        ->loadEntityByUuid($entity_type_id, $uuid);
      $link
        ->delete();
      $total_count++;
    }
    if ($total_count) {
      drupal_set_message($this
        ->formatPlural($total_count, 'Deleted 1 menu item.', 'Deleted @count menu items.'));
    }
    $this->tempStoreFactory
      ->get('menu_delete_item_confirm')
      ->delete(\Drupal::currentUser()
      ->id());
  }
  $form_state
    ->setRedirect('entity.menu.edit_form', array(
    'menu' => $this->menuId,
  ));
}