diff --git a/core/modules/user/lib/Drupal/user/Controller/UserController.php b/core/modules/user/lib/Drupal/user/Controller/UserController.php index eb1dbde..3229c12 100644 --- a/core/modules/user/lib/Drupal/user/Controller/UserController.php +++ b/core/modules/user/lib/Drupal/user/Controller/UserController.php @@ -7,15 +7,45 @@ namespace Drupal\user\Controller; +use Drupal\Core\Controller\ControllerInterface; +use Drupal\Core\Entity\EntityRenderControllerInterface; use Drupal\user\Form\UserLoginForm; +use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; /** * Controller routines for user routes. */ -class UserController extends ContainerAware { +class UserController extends ContainerAware implements ControllerInterface { + + /** + * The user render controller. + * + * @var \Drupal\Core\Entity\EntityRenderControllerInterface + */ + protected $renderController; + + /** + * Constructs a new UserController object. + * + * @param \Drupal\Core\Entity\EntityRenderControllerInterface $render_controller + * The user render controller. + */ + public function __construct(EntityRenderControllerInterface $render_controller) { + $this->renderController = $render_controller; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity')->getRenderController('user') + ); + } /** * Returns the user page. @@ -55,4 +85,17 @@ public function logout(Request $request) { return new RedirectResponse(url('', array('absolute' => TRUE))); } + /** + * Displays a user account page. + * + * @param \Drupal\user\UserInterface $account + * User account to display. + * + * @return array + * The user page. + */ + public function viewPage(UserInterface $account) { + return $this->renderController->view($account->getBCEntity()); + } + } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index db9f833..a1d0883 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -956,10 +956,7 @@ function user_menu() { 'title' => 'My account', 'title callback' => 'user_page_title', 'title arguments' => array(1), - 'page callback' => 'user_view_page', - 'page arguments' => array(1), - 'access callback' => 'entity_page_access', - 'access arguments' => array(1), + 'route_name' => 'user_view_page', ); $items['user/%user/view'] = array( 'title' => 'View', @@ -1120,8 +1117,8 @@ function user_menu_title() { /** * Menu item title callback - use the user name. */ -function user_page_title(UserInterface $account = NULL) { - return $account ? $account->getUsername() : ''; +function user_page_title(UserInterface $account) { + return $account->getUsername(); } /** @@ -1453,18 +1450,6 @@ function user_delete_multiple(array $uids) { } /** - * Page callback wrapper for user_view(). - */ -function user_view_page($account) { - if (is_object($account)) { - return user_view($account); - } - // An administrator may try to view a non-existent account, - // so we give them a 404 (versus a 403 for non-admins). - throw new NotFoundHttpException(); -} - -/** * Generate an array for rendering the given user. * * When viewing a user profile, the $page array contains: diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml index 10ec95d..b30f281 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -88,3 +88,13 @@ user_login: _form: '\Drupal\user\Form\UserLoginForm' requirements: _access: 'TRUE' + +user_view_page: + pattern: '/user/{account}' + options: + converters: + account: 'user' + defaults: + _controller: '\Drupal\user\Controller\UserController::viewPage' + requirements: + _entity_access: 'account.view'