diff --git a/core/modules/contact/contact.routing.yml b/core/modules/contact/contact.routing.yml index 8538973..8d6132a 100644 --- a/core/modules/contact/contact.routing.yml +++ b/core/modules/contact/contact.routing.yml @@ -3,4 +3,4 @@ contact_category_delete: defaults: _form: '\Drupal\contact\Form\DeleteForm' requirements: - _access_category_delete: 'TRUE' + _entity_access: 'contact_category.delete' diff --git a/core/modules/contact/lib/Drupal/contact/Access/ContactDeleteAccessCheck.php b/core/modules/contact/lib/Drupal/contact/Access/ContactDeleteAccessCheck.php deleted file mode 100644 index 1d547aa..0000000 --- a/core/modules/contact/lib/Drupal/contact/Access/ContactDeleteAccessCheck.php +++ /dev/null @@ -1,34 +0,0 @@ -getRequirements()); - } - - /** - * Implements AccessCheckInterface::access(). - */ - public function access(Route $route, Request $request) { - $entity = $request->attributes->get('contact_category'); - return user_access('administer contact forms') && ($entity && $entity->id() != 'user'); - } - -} diff --git a/core/modules/contact/lib/Drupal/contact/CategoryAccessController.php b/core/modules/contact/lib/Drupal/contact/CategoryAccessController.php new file mode 100644 index 0000000..62c0dfa --- /dev/null +++ b/core/modules/contact/lib/Drupal/contact/CategoryAccessController.php @@ -0,0 +1,29 @@ +id() !== 'user'; + } + +} diff --git a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php index 498345e..d00e84b 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php @@ -37,6 +37,7 @@ public function form(array $form, array &$form_state, EntityInterface $category) '#machine_name' => array( 'exists' => 'contact_category_load', ), + // Do not allow change 'user' category used for personal contact form. '#disabled' => !$category->isNew() || $category->id() == 'user', ); $form['recipients'] = array( @@ -73,6 +74,18 @@ public function form(array $form, array &$form_state, EntityInterface $category) } /** + * {@inheritdoc} + */ + protected function actions(array $form, array &$form_state) { + $actions = parent::actions($form, $form_state); + + $actions['delete']['#access'] = $this->getEntity($form_state)->access('delete'); + + return $actions; + + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::validate(). */ public function validate(array $form, array &$form_state) { diff --git a/core/modules/contact/lib/Drupal/contact/CategoryListController.php b/core/modules/contact/lib/Drupal/contact/CategoryListController.php index 420299e..25ef7fc 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryListController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryListController.php @@ -34,8 +34,8 @@ public function getOperations(EntityInterface $entity) { 'weight' => 12, ); } - // Do not allow delete 'user' category used for personal contact form. - if ($entity->id() == 'user') { + + if (!$entity->access('delete')) { unset($operations['delete']); } return $operations; diff --git a/core/modules/contact/lib/Drupal/contact/ContactBundle.php b/core/modules/contact/lib/Drupal/contact/ContactBundle.php deleted file mode 100644 index 218abd7..0000000 --- a/core/modules/contact/lib/Drupal/contact/ContactBundle.php +++ /dev/null @@ -1,27 +0,0 @@ -register('access_check.contact.delete', 'Drupal\contact\Access\ContactDeleteAccessCheck') - ->addTag('access_check'); - } - -} diff --git a/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php b/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php index afb3ff0..d06a827 100644 --- a/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php +++ b/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php @@ -20,6 +20,7 @@ * module = "contact", * controllers = { * "storage" = "Drupal\contact\CategoryStorageController", + * "access" = "Drupal\contact\CategoryAccessController", * "list" = "Drupal\contact\CategoryListController", * "form" = { * "default" = "Drupal\contact\CategoryFormController"