Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
user_current_paths
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
user_current_paths
Merge requests
!2
Issue
#3184322
: "user/current/{action}" not working
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3184322
: "user/current/{action}" not working
issue/user_current_paths-3184322:3184322-usercurrentaction-not-working
into
2.0.x
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
Julian Pustkuchen
requested to merge
issue/user_current_paths-3184322:3184322-usercurrentaction-not-working
into
2.0.x
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Compare
2.0.x
2.0.x (base)
and
latest version
latest version
55089890
1 commit,
3 years ago
3 files
+
73
−
29
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/Controller/UserCurrentPathsController.php
+
64
−
26
Options
@@ -2,54 +2,92 @@
namespace
Drupal\user_current_paths\Controller
;
use
Drupal\Core\Session\AccountInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Url
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Session\AccountProxy
;
use
Drupal\Core\Path\PathValidator
;
class
UserCurrentPathsController
extends
ControllerBase
{
/**
* Defines the User Current Paths controller.
*/
class
UserCurrentPathsController
extends
ControllerBase
{
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxy
*/
protected
$currentUser
;
/**
* The path validator.
*
* @var \Drupal\Core\Path\PathValidator
*/
protected
$pathValidator
;
/**
* Constructs a UserCurrentPathsController object.
*
* @param \Drupal\Core\Session\AccountProxy $current_user
* The current user.
* @param \Drupal\Core\Path\PathValidator $path_validator
* The path validator.
*/
public
function
__construct
(
AccountProxy
$current_user
,
PathValidator
$path_validator
)
{
$this
->
currentUser
=
$current_user
;
$this
->
pathValidator
=
$path_validator
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'current_user'
),
$container
->
get
(
'path.validator'
)
);
}
/**
* Handles wildcard (user/current/*) redirects for the current user.
* Replaces the second "current" parameter in the URL with the currently logged in user
* and redirects to the target if the resulting path is valid. Ohterwise throws a NotFoundHttpException.
* This is safe because the redirect is handled as if the user entered the URL manually with all security checks.
*
* Replaces the second "current" parameter in the URL with the currently
* logged in user and redirects to the target if the resulting path is valid.
* Ohterwise throws a NotFoundHttpException. This is safe because the redirect
* is handled as if the user entered the URL manually with all security
* checks.
*
* @param string $wildcardaction
* @param Request $request
* @return void
* The wildcart action.
*/
public
function
wildcardActionRedirect
(
$wildcardaction
=
'view'
,
Request
$request
)
{
$currentUserId
=
(
int
)
\Drupal
::
currentUser
()
->
id
();
$path
=
'/user/'
.
$currentUserId
;
public
function
wildcardActionRedirect
(
string
$wildcardaction
)
{
$path
=
'/user/'
.
$this
->
currentUser
->
id
();
if
(
$wildcardaction
!=
'view'
)
{
// /view doesn't exist for user entities
$path
.
=
'/'
.
$wildcardaction
;
}
$url
=
\Drupal
::
service
(
'path.validator'
)
->
getUrlIfValid
(
$path
);
if
(
$url
!==
false
)
{
$url
=
$this
->
pathValidator
->
getUrlIfValid
(
$path
);
if
(
$url
!==
FALSE
)
{
// Valid internal path:
return
$this
->
redirect
(
$url
);
}
else
{
throw
new
NotFoundHttpException
();
return
$this
->
redirect
(
$url
->
getRouteName
(),
$url
->
getRouteParameters
(),
$url
->
getOptions
());
}
throw
new
NotFoundHttpException
();
}
/**
* Handles redirects to the user edit page (user/edit) for the currently logged in user.
*
* @param Request $request
* @return void
* Handles redirects to the user edit page for the currently logged in user.
*/
public
function
editRedirect
(
Request
$request
)
{
public
function
editRedirect
()
{
$route_name
=
'entity.user.edit_form'
;
$route_parameters
=
[
'user'
=>
\Drupal
::
currentUser
()
->
id
(),
'user'
=>
$this
->
currentUser
->
id
(),
];
return
$this
->
redirect
(
$route_name
,
$route_parameters
);
}
}
Loading