Commit 29c84544 authored by webchick's avatar webchick

Issue #1920686 by swentel: Fixed Deleting a menu gives fatal error + the...

Issue #1920686 by swentel: Fixed Deleting a menu gives fatal error + the delete button is shown on system menu's.
parent cedf8d3f
...@@ -64,22 +64,22 @@ public function form(array $form, array &$form_state, EntityInterface $menu) { ...@@ -64,22 +64,22 @@ public function form(array $form, array &$form_state, EntityInterface $menu) {
$form['links'] = menu_overview_form($form['links'], $form_state); $form['links'] = menu_overview_form($form['links'], $form_state);
} }
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#button_type' => 'primary',
);
// Only custom menus may be deleted.
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#access' => !$menu->isNew() && !isset($system_menus[$menu->id()]),
);
return $form; return $form;
} }
/**
* Overrides Drupal\Core\Entity\EntityFormController::actions().
*/
protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
$menu = $this->getEntity($form_state);
$system_menus = menu_list_system_menus();
$actions['delete']['#access'] = !$menu->isNew() && !isset($system_menus[$menu->id()]);
return $actions;
}
/** /**
* Overrides Drupal\Core\Entity\EntityFormController::save(). * Overrides Drupal\Core\Entity\EntityFormController::save().
*/ */
......
...@@ -182,6 +182,14 @@ function deleteCustomMenu($menu) { ...@@ -182,6 +182,14 @@ function deleteCustomMenu($menu) {
// Test if all menu links associated to the menu were removed from database. // Test if all menu links associated to the menu were removed from database.
$result = entity_load_multiple_by_properties('menu_link', array('menu_name' => $menu_name)); $result = entity_load_multiple_by_properties('menu_link', array('menu_name' => $menu_name));
$this->assertFalse($result, 'All menu links associated to the custom menu were deleted.'); $this->assertFalse($result, 'All menu links associated to the custom menu were deleted.');
// Make sure there's no delete button on system menus.
$this->drupalGet('admin/structure/menu/manage/main/edit');
$this->assertNoRaw('edit-delete', 'The delete button was not found');
// Try to delete the main menu.
$this->drupalGet('admin/structure/menu/manage/main/delete');
$this->assertText(t('You are not authorized to access this page.'));
} }
/** /**
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
use Drupal\menu_link\Plugin\Core\Entity\MenuLink; use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
use Drupal\system\Plugin\Core\Entity\Menu; use Drupal\system\Plugin\Core\Entity\Menu;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* Menu callback which shows an overview page of all the custom menus and their descriptions. * Menu callback which shows an overview page of all the custom menus and their descriptions.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment