You are here

function menu_delete_form_alter in Menu Delete 8

Same name and namespace in other branches
  1. 8.2 menu_delete.module \menu_delete_form_alter()

Implements hook_form_alter().

File

./menu_delete.module, line 14
Contains menu_delete.module.

Code

function menu_delete_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form['#form_id'] == 'menu_edit_form') {
    $form['links']['links']['#header'][] = array(
      'data' => t('Delete'),
      'class' => array(
        'checkbox',
      ),
    );
    foreach (Element::children($form['links']['links']) as $id) {
      $form['links']['links'][$id]['delete'] = array();

      // Add a checkbox to all menu items that can be deleted.
      if ($form['links']['links'][$id]['#item']->link
        ->isDeletable()) {
        $form['links']['links'][$id]['delete'] = array(
          '#type' => 'checkbox',
          '#title' => t('Delete'),
          '#title_display' => 'invisible',
          '#default_value' => FALSE,
          '#wrapper_attributes' => array(
            'class' => array(
              'checkbox',
              'menu-delete',
            ),
          ),
        );
      }
    }
    $form['actions']['delete_selected'] = array(
      '#type' => 'submit',
      '#value' => t('Delete selected'),
      '#button_type' => 'secondary',
      '#weight' => 10,
      '#submit' => array(
        'menu_delete_edit_form_submit',
      ),
    );
  }
}