diff --git a/core/includes/entity.inc b/core/includes/entity.inc index e5d2ae5..32fed26 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -666,3 +666,18 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) { function entity_query($entity_type, $conjunction = 'AND') { return drupal_container()->get('entity.query')->get($entity_type, $conjunction); } + +/** + * Generic access callback for entity pages. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity for which access is being checked. + * @param string $operation + * (optional) The operation being performed on the entity. Defaults to 'view'. + * + * @return bool + * TRUE if the access is granted. FALSE if access is denied. + */ +function entity_page_access(EntityInterface $entity, $operation = 'view') { + return $entity->access($operation); +} diff --git a/core/modules/user/user.module b/core/modules/user/user.module index c48d533..2ae73e9 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -834,48 +834,6 @@ function user_register_access() { } /** - * User view access callback. - * - * @param \Drupal\user\Plugin\Core\Entity\User $account - * Account to check view access against. - * - * @return bool - * TRUE if permission to view given account is granted, otherwise FALSE. - */ -function user_view_access(User $account) { - return $account->access('view'); -} - -/** - * Access callback for user account editing. - * - * @param \Drupal\user\Plugin\Core\Entity\User $account - * Account to check edit access against. - * - * @return bool - * TRUE if permission to edit given account is granted, otherwise FALSE. - */ -function user_edit_access(User $account) { - return $account->access('update'); -} - -/** - * Menu access callback; limit access to account cancellation pages. - * - * Limit access to users with the 'cancel account' permission or administrative - * users, and prevent the anonymous user from cancelling the account. - * - * @param \Drupal\user\Plugin\Core\Entity\User $account - * Account to check cancel access against. - * - * @return bool - * TRUE if permission to cancel given account is granted, otherwise FALSE. - */ -function user_cancel_access(User $account) { - return $account->access('delete'); -} - -/** * Implements hook_menu(). */ function user_menu() { @@ -1041,7 +999,7 @@ function user_menu() { 'title arguments' => array(1), 'page callback' => 'user_view_page', 'page arguments' => array(1), - 'access callback' => 'user_view_access', + 'access callback' => 'entity_page_access', 'access arguments' => array(1), ); @@ -1055,8 +1013,8 @@ function user_menu() { 'title' => 'Cancel account', 'page callback' => 'drupal_get_form', 'page arguments' => array('user_cancel_confirm_form', 1), - 'access callback' => 'user_cancel_access', - 'access arguments' => array(1), + 'access callback' => 'entity_page_access', + 'access arguments' => array(1, 'delete'), 'file' => 'user.pages.inc', ); @@ -1064,8 +1022,8 @@ function user_menu() { 'title' => 'Confirm account cancellation', 'page callback' => 'user_cancel_confirm', 'page arguments' => array(1, 4, 5), - 'access callback' => 'user_cancel_access', - 'access arguments' => array(1), + 'access callback' => 'entity_page_access', + 'access arguments' => array(1, 'delete'), 'file' => 'user.pages.inc', ); @@ -1073,8 +1031,8 @@ function user_menu() { 'title' => 'Edit', 'page callback' => 'entity_get_form', 'page arguments' => array(1, 'profile'), - 'access callback' => 'user_edit_access', - 'access arguments' => array(1), + 'access callback' => 'entity_page_access', + 'access arguments' => array(1, 'edit'), 'type' => MENU_LOCAL_TASK, 'file' => 'user.pages.inc', );