diff --git a/core/modules/tracker/lib/Drupal/tracker/Access/OwnTrackingInformation.php b/core/modules/tracker/lib/Drupal/tracker/Access/OwnTrackingInformation.php new file mode 100644 index 0000000..c674379 --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Access/OwnTrackingInformation.php @@ -0,0 +1,32 @@ +getRequirements()); + } + + /** + * Implements AccessCheckInterface::access(). + */ + public function access(Route $route, Request $request) { + return ($account = user_uid_optional_load(arg(1))) && $account->uid && ($GLOBALS['user']->uid == $account->uid) && user_access('access content'); + } +} diff --git a/core/modules/tracker/lib/Drupal/tracker/Access/UserTab.php b/core/modules/tracker/lib/Drupal/tracker/Access/UserTab.php new file mode 100644 index 0000000..9e25492 --- /dev/null +++ b/core/modules/tracker/lib/Drupal/tracker/Access/UserTab.php @@ -0,0 +1,32 @@ +getRequirements()); + } + + /** + * Implements AccessCheckInterface::access(). + */ + public function access(Route $route, Request $request) { + return ($account = user_load(arg(1), TRUE)) && $account->access('view') && user_access('access content'); + } +} diff --git a/core/modules/tracker/lib/Drupal/tracker/Controller/TrackerController.php b/core/modules/tracker/lib/Drupal/tracker/Controller/TrackerController.php index c781618..1e99a5d 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Controller/TrackerController.php +++ b/core/modules/tracker/lib/Drupal/tracker/Controller/TrackerController.php @@ -1,5 +1,4 @@ get('database'), + $container->get('plugin.manager.entity') + ); + } + + /** * Constructs a TrackerController object. * * @param \Drupal\Core\Database\Connection $database @@ -45,16 +52,6 @@ public function __construct(Connection $database, EntityManager $entity_manager) } /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('database'), - $container->get('plugin.manager.entity') - ); - } - - /** * Generates a page of tracked nodes for the site. * * Queries the database for info, adds RDFa info if applicable, and generates @@ -66,8 +63,10 @@ public static function create(ContainerInterface $container) { * TRUE if the title of the page should be replaced by the username, * else FALSE. Defaults to FALSE. * + * * @return array * A renderable array. + * */ public function trackerPage($account = NULL, $set_title = FALSE) { if ($account) { @@ -195,5 +194,4 @@ public function trackerPage($account = NULL, $set_title = FALSE) { return $page; } - } diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index 18b7cda..22d2728 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -43,22 +43,13 @@ function tracker_menu() { ); $items['tracker/%user_uid_optional'] = array( 'title' => 'My recent content', - 'page callback' => 'tracker_page', - 'access callback' => '_tracker_myrecent_access', - 'access arguments' => array(1), - 'page arguments' => array(1), + 'route_name' => 'tracker_users_recent_content', 'type' => MENU_LOCAL_TASK, - 'file' => 'tracker.pages.inc', ); - $items['user/%user/track'] = array( 'title' => 'Track', - 'page callback' => 'tracker_page', - 'page arguments' => array(1, TRUE), - 'access callback' => '_tracker_user_access', - 'access arguments' => array(1), + 'route_name' => 'tracker_user_tab', 'type' => MENU_LOCAL_TASK, - 'file' => 'tracker.pages.inc', ); $items['user/%user/track/content'] = array( 'title' => 'Track content', @@ -154,39 +145,6 @@ function tracker_cron() { } /** - * Access callback: Determines access permission for a user's own account. - * - * @param int $account - * The account ID to check. - * - * @return boolean - * TRUE if a user is accessing tracking info for their own account and - * has permission to access the content. - * - * @see tracker_menu() - */ -function _tracker_myrecent_access($account) { - // This path is only allowed for authenticated users looking at their own content. - return $account->uid && ($GLOBALS['user']->uid == $account->uid) && user_access('access content'); -} - -/** - * Access callback: Determines access permission for an account. - * - * @param int $account - * The user account ID to track. - * - * @return boolean - * TRUE if a user has permission to access the account for $account and - * has permission to access the content. - * - * @see tracker_menu() - */ -function _tracker_user_access($account) { - return $account->access('view') && user_access('access content'); -} - -/** * Implements hook_node_insert(). * * Adds new tracking information for this node since it's new. diff --git a/core/modules/tracker/tracker.routing.yml b/core/modules/tracker/tracker.routing.yml index b4c709e..f591b8d 100644 --- a/core/modules/tracker/tracker.routing.yml +++ b/core/modules/tracker/tracker.routing.yml @@ -4,3 +4,17 @@ tracker_page: _content: '\Drupal\tracker\Controller\TrackerController::trackerPage' requirements: _permission: 'access content' + +tracker_users_recent_content: + pattern: '/tracker/{user_uid_optional}' + defaults: + _content: '\Drupal\tracker\Controller\TrackerController::trackerPage' + requirements: + _access_tracker_own_information: 'TRUE' + +tracker_user_tab: + pattern: '/user/{user}/track' + defaults: + _content: '\Drupal\tracker\Controller\TrackerController::trackerPage' + requirements: + _access_tracker_user_tab: 'TRUE' \ No newline at end of file diff --git a/core/modules/tracker/tracker.services.yml b/core/modules/tracker/tracker.services.yml new file mode 100644 index 0000000..90d1ce3 --- /dev/null +++ b/core/modules/tracker/tracker.services.yml @@ -0,0 +1,9 @@ +services: + access_check.tracker.own_information: + class: Drupal\tracker\Access\OwnTrackingInformation + tags: + - { name: access_check } + access_check.tracker.user_tab: + class: Drupal\tracker\Access\UserTab + tags: + - { name: access_check }