Commit e952a211 authored by catch's avatar catch

Revert "Issue #2012916 by andypost: Implement access controller for the menu and menu link entity."

This reverts commit 0f480b9e.
parent 57384c7b
<?php
/**
* @file
* Contains \Drupal\menu\Access\DeleteLinkAccessCheck.
*/
namespace Drupal\menu\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Access check for menu link delete routes.
*/
class DeleteLinkAccessCheck implements AccessCheckInterface {
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return array_key_exists('_access_menu_delete_link', $route->getRequirements());
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
if (user_access('administer menu') && $menu_link = $request->attributes->get('menu_link')) {
// Links defined via hook_menu may not be deleted. Updated items are an
// exception, as they can be broken.
return $menu_link->module !== 'system' || $menu_link->updated;
}
return FALSE;
}
}
<?php
/**
* @file
* Contains \Drupal\menu\Access\DeleteMenuAccessCheck.
*/
namespace Drupal\menu\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Access check for menu delete routes.
*/
class DeleteMenuAccessCheck implements AccessCheckInterface {
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return array_key_exists('_access_menu_delete_menu', $route->getRequirements());
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
if (user_access('administer menu') && $menu = $request->attributes->get('menu')) {
// System-defined menus may not be deleted.
$system_menus = menu_list_system_menus();
return !isset($system_menus[$menu->id()]);
}
return FALSE;
}
}
......@@ -71,8 +71,10 @@ public function form(array $form, array &$form_state) {
*/
protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
$menu = $this->entity;
$actions['delete']['#access'] = !$this->entity->isNew() && $this->entity->access('delete');
$system_menus = menu_list_system_menus();
$actions['delete']['#access'] = !$menu->isNew() && !isset($system_menus[$menu->id()]);
return $actions;
}
......@@ -112,7 +114,8 @@ public function save(array $form, array &$form_state) {
* Overrides Drupal\Core\Entity\EntityFormController::delete().
*/
public function delete(array $form, array &$form_state) {
$form_state['redirect'] = 'admin/structure/menu/manage/' . $this->entity->id() . '/delete';
$menu = $this->entity;
$form_state['redirect'] = 'admin/structure/menu/manage/' . $menu->id() . '/delete';
}
}
......@@ -55,11 +55,13 @@ public function getOperations(EntityInterface $entity) {
'options' => $uri['options'],
'weight' => 20,
);
if ($entity->access('delete')) {
$operations['delete']['title'] = t('Delete menu');
// System menus could not be deleted.
$system_menus = menu_list_system_menus();
if (isset($system_menus[$entity->id()])) {
unset($operations['delete']);
}
else {
unset($operations['delete']);
$operations['delete']['title'] = t('Delete menu');
}
return $operations;
}
......
......@@ -125,6 +125,7 @@ function menu_overview_form($form, &$form_state) {
function _menu_overview_tree_form($tree, $delta = 50) {
$form = &drupal_static(__FUNCTION__, array('#tree' => TRUE));
foreach ($tree as $data) {
$title = '';
$item = $data['link'];
// Don't show callbacks; these have $item['hidden'] < 0.
if ($item && $item['hidden'] >= 0) {
......
......@@ -17,11 +17,11 @@ menu_link_delete:
defaults:
_form: '\Drupal\menu\Form\MenuLinkDeleteForm'
requirements:
_entity_access: menu_link.delete
_access_menu_delete_link: 'TRUE'
menu_delete_menu:
pattern: 'admin/structure/menu/manage/{menu}/delete'
defaults:
_form: '\Drupal\menu\Form\MenuDeleteMenuForm'
requirements:
_entity_access: menu.delete
_access_menu_delete_menu: 'TRUE'
services:
access_check.menu.delete_link:
class: Drupal\menu\Access\DeleteLinkAccessCheck
tags:
- { name: access_check }
access_check.menu.delete_menu:
class: Drupal\menu\Access\DeleteMenuAccessCheck
tags:
- { name: access_check }
<?php
/**
* @file
* Contains \Drupal\menu_link\MenuLinkAccessController.
*/
namespace Drupal\menu_link;
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\Plugin\Core\Entity\User;
/**
* Defines an access controller for the menu link entity.
*
* @see \Drupal\menu_link\Plugin\Core\Entity\MenuLink
*/
class MenuLinkAccessController extends EntityAccessController {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) {
$access = user_access('administer menu', $account);
if ($access && $operation == 'delete') {
// Only items created by the menu module can be deleted.
return $entity->module == 'menu';
}
return $access;
}
}
......@@ -172,7 +172,7 @@ public function form(array $form, array &$form_state) {
protected function actions(array $form, array &$form_state) {
$element = parent::actions($form, $form_state);
$element['submit']['#button_type'] = 'primary';
$element['delete']['#access'] = $this->entity->access('delete');
$element['delete']['#access'] = $this->entity->module == 'menu';
return $element;
}
......
......@@ -24,7 +24,6 @@
* module = "menu_link",
* controllers = {
* "storage" = "Drupal\menu_link\MenuLinkStorageController",
* "access" = "Drupal\menu_link\MenuLinkAccessController",
* "render" = "Drupal\Core\Entity\EntityRenderController",
* "form" = {
* "default" = "Drupal\menu_link\MenuLinkFormController"
......
<?php
/**
* @file
* Contains \Drupal\system\MenuAccessController.
*/
namespace Drupal\system;
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\Plugin\Core\Entity\User;
/**
* Defines an access controller for the menu entity.
*
* @see \Drupal\system\Plugin\Core\Entity\Menu
*/
class MenuAccessController extends EntityAccessController {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) {
if ($operation == 'delete') {
// System-defined menus may not be deleted.
// @todo Refactor https://drupal.org/node/1882552
$system_menus = menu_list_system_menus();
return !isset($system_menus[$entity->id()]);
}
return user_access('administer menu', $account);
}
}
......@@ -20,8 +20,7 @@
* label = @Translation("Menu"),
* module = "system",
* controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
* "access" = "Drupal\system\MenuAccessController"
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
* },
* config_prefix = "menu.menu",
* entity_keys = {
......
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