Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
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
drupal
Merge requests
!3345
Issue
#2904908
: Fetch "User ID from route context" views' contextual filter for any entity
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#2904908
: Fetch "User ID from route context" views' contextual filter for any entity
issue/drupal-2904908:2904908-fetch-user-id
into
10.1.x
Overview
0
Commits
1
Pipelines
0
Changes
3
Open
Bhanu D
requested to merge
issue/drupal-2904908:2904908-fetch-user-id
into
10.1.x
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Compare
10.1.x
10.1.x (HEAD)
and
latest version
latest version
2942899c
1 commit,
2 years ago
3 files
+
272
−
35
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
core/modules/user/src/Plugin/views/argument_default/User.php
+
9
−
35
Options
@@ -4,12 +4,11 @@
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Cache\CacheableDependencyInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\views\Plugin\views\argument_default
\ArgumentDefaultPluginBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\user\UserInterface
;
use
Drupal\
node\Node
Interface
;
use
Drupal\
user\EntityOwner
Interface
;
/**
* Default argument plugin to extract a user from request.
@@ -58,43 +57,18 @@ public static function create(ContainerInterface $container, array $configuratio
);
}
/**
* {@inheritdoc}
*/
protected
function
defineOptions
()
{
$options
=
parent
::
defineOptions
();
$options
[
'user'
]
=
[
'default'
=>
''
];
return
$options
;
}
/**
* {@inheritdoc}
*/
public
function
buildOptionsForm
(
&
$form
,
FormStateInterface
$form_state
)
{
$form
[
'user'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Also look for a node and use the node author'
),
'#default_value'
=>
$this
->
options
[
'user'
],
];
}
/**
* {@inheritdoc}
*/
public
function
getArgument
()
{
// If there is a user object in the current route.
if
(
$user
=
$this
->
routeMatch
->
getParameter
(
'user'
))
{
if
(
$user
instanceof
UserInterface
)
{
return
$user
->
id
();
}
}
// If option to use node author; and node in current route.
if
(
!
empty
(
$this
->
options
[
'user'
])
&&
$node
=
$this
->
routeMatch
->
getParameter
(
'node'
))
{
if
(
$node
instanceof
NodeInterface
)
{
return
$node
->
getOwnerId
();
if
(
$parameters
=
$this
->
routeMatch
->
getParameters
())
{
foreach
(
$parameters
->
all
()
as
$entity
)
{
if
(
$entity
instanceof
UserInterface
)
{
return
$entity
->
id
();
}
elseif
(
$entity
instanceof
EntityOwnerInterface
)
{
return
$entity
->
getOwnerId
();
}
}
}
}
Loading