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
Commits
44c9add9
Commit
44c9add9
authored
11 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2095961
by ekes: Remove instances of menu_get_object('user').
parent
fef7427c
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/user/lib/Drupal/user/Plugin/views/argument_default/User.php
+62
-34
62 additions, 34 deletions
...er/lib/Drupal/user/Plugin/views/argument_default/User.php
with
62 additions
and
34 deletions
core/modules/user/lib/Drupal/user/Plugin/views/argument_default/User.php
+
62
−
34
View file @
44c9add9
...
...
@@ -7,21 +7,62 @@
namespace
Drupal\user\Plugin\views\argument_default
;
use
Drupal\Component\Annotation\Plugin
;
use
Drupal\views\Annotation\ViewsArgumentDefault
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\views\Plugin\views\argument_default
\ArgumentDefaultPluginBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Drupal\user\UserInterface
;
use
Drupal\node\NodeInterface
;
/**
* Default argument plugin to extract a user
via menu_get_objec
t.
* Default argument plugin to extract a user
from reques
t.
*
* @ViewsArgumentDefault(
* id = "user",
* title = @Translation("User ID from
URL
")
* title = @Translation("User ID from
route context
")
* )
*/
class
User
extends
ArgumentDefaultPluginBase
{
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected
$request
;
/**
* Constructs a default argument User object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
array
$plugin_definition
,
Request
$request
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
request
=
$request
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
array
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'request'
)
);
}
/**
* {@inheritdoc}
*/
protected
function
defineOptions
()
{
$options
=
parent
::
defineOptions
();
$options
[
'user'
]
=
array
(
'default'
=>
''
,
'bool'
=>
TRUE
,
'translatable'
=>
FALSE
);
...
...
@@ -29,6 +70,9 @@ protected function defineOptions() {
return
$options
;
}
/**
* {@inheritdoc}
*/
public
function
buildOptionsForm
(
&
$form
,
&
$form_state
)
{
$form
[
'user'
]
=
array
(
'#type'
=>
'checkbox'
,
...
...
@@ -37,44 +81,28 @@ public function buildOptionsForm(&$form, &$form_state) {
);
}
/**
* {@inheritdoc}
*/
public
function
getArgument
()
{
foreach
(
range
(
1
,
3
)
as
$i
)
{
$user
=
menu_get_object
(
'user'
,
$i
);
if
(
!
empty
(
$user
))
{
return
$user
->
id
();
}
}
foreach
(
range
(
1
,
3
)
as
$i
)
{
$user
=
menu_get_object
(
'user_uid_optional'
,
$i
);
if
(
!
empty
(
$user
))
{
// If there is a user object in the current route.
if
(
$this
->
request
->
attributes
->
has
(
'user'
))
{
$user
=
$this
->
request
->
attributes
->
get
(
'user'
);
if
(
$user
instanceof
UserInterface
)
{
return
$user
->
id
();
}
}
if
(
!
empty
(
$this
->
options
[
'user'
]))
{
foreach
(
range
(
1
,
3
)
as
$i
)
{
$node
=
menu_get_object
(
'node'
,
$i
);
if
(
!
empty
(
$node
))
{
return
$node
->
getAuthorId
();
}
}
}
if
(
arg
(
0
)
==
'user'
&&
is_numeric
(
arg
(
1
)))
{
return
arg
(
1
);
}
if
(
!
empty
(
$this
->
options
[
'user'
]))
{
if
(
arg
(
0
)
==
'node'
&&
is_numeric
(
arg
(
1
)))
{
$node
=
node_load
(
arg
(
1
));
if
(
$node
)
{
return
$node
->
getAuthorId
();
}
// If option to use node author; and node in current route.
if
(
!
empty
(
$this
->
options
[
'user'
])
&&
$this
->
request
->
attributes
->
has
(
'node'
))
{
$node
=
$this
->
request
->
attributes
->
get
(
'node'
);
if
(
$node
instanceof
NodeInterface
)
{
return
$node
->
getAuthorId
();
}
}
// If the current page is a view that takes uid as an argument
, return the uid
.
// If the current page is a view that takes uid as an argument.
$view
=
views_get_page_view
();
if
(
$view
&&
isset
(
$view
->
argument
[
'uid'
]))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment