Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
707c3d2f
Commit
707c3d2f
authored
Dec 10, 2012
by
Nathaniel Catchpole
Browse files
Issue
#1859884
by dawehner: Convert user link fields to use entities.
parent
08df7b0d
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php
View file @
707c3d2f
...
...
@@ -9,6 +9,7 @@
use
Drupal\views\Plugin\views\field\FieldPluginBase
;
use
Drupal\views\ViewExecutable
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Annotation\Plugin
;
/**
...
...
@@ -57,16 +58,29 @@ public function query() {
$this
->
add_additional_fields
();
}
/**
* Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render().
*/
function
render
(
$values
)
{
$value
=
$this
->
get_value
(
$values
,
'uid'
);
return
$this
->
render_link
(
$this
->
sanitizeValue
(
$value
),
$values
);
return
$this
->
render_link
(
$this
->
get_entity
(
$values
),
$values
);
}
function
render_link
(
$data
,
$values
)
{
/**
* Alters the field to render a link.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \stdClass $values
* The current row of the views result.
*
* @return string
* The acutal rendered text (without the link) of this field.
*/
public
function
render_link
(
EntityInterface
$entity
,
\
stdClass
$values
)
{
$text
=
!
empty
(
$this
->
options
[
'text'
])
?
$this
->
options
[
'text'
]
:
t
(
'view'
);
$this
->
options
[
'alter'
][
'make_link'
]
=
TRUE
;
$this
->
options
[
'alter'
][
'path'
]
=
"user/"
.
$data
;
$uri
=
$entity
->
uri
();
$this
->
options
[
'alter'
][
'path'
]
=
$uri
[
'path'
];
return
$text
;
}
...
...
core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php
View file @
707c3d2f
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\user\Plugin\views\field
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Annotation\Plugin
;
/**
...
...
@@ -21,19 +22,17 @@
*/
class
LinkCancel
extends
Link
{
function
render_link
(
$data
,
$values
)
{
$uid
=
$values
->
{
$this
->
aliases
[
'uid'
]};
// Build a pseudo account object to be able to check the access.
$account
=
entity_create
(
'user'
,
array
());
$account
->
uid
=
$uid
;
if
(
$uid
&&
user_cancel_access
(
$account
))
{
/**
* Overrides \Drupal\user\Plugin\views\field\Link::render_link().
*/
public
function
render_link
(
EntityInterface
$entity
,
\
stdClass
$values
)
{
if
(
$entity
&&
user_cancel_access
(
$entity
))
{
$this
->
options
[
'alter'
][
'make_link'
]
=
TRUE
;
$text
=
!
empty
(
$this
->
options
[
'text'
])
?
$this
->
options
[
'text'
]
:
t
(
'cancel'
);
$this
->
options
[
'alter'
][
'path'
]
=
"user/
$uid
/cancel"
;
$uri
=
$entity
->
uri
();
$this
->
options
[
'alter'
][
'path'
]
=
$uri
[
'path'
]
.
'/cancel'
;
$this
->
options
[
'alter'
][
'query'
]
=
drupal_get_destination
();
return
$text
;
...
...
core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php
View file @
707c3d2f
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\user\Plugin\views\field
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Annotation\Plugin
;
/**
...
...
@@ -21,17 +22,17 @@
*/
class
LinkEdit
extends
Link
{
function
render_link
(
$data
,
$values
)
{
// Build a pseudo account object to be able to check the access.
$account
=
entity_create
(
'user'
,
array
());
$account
->
uid
=
$data
;
if
(
$data
&&
user_edit_access
(
$account
))
{
/**
* Overrides \Drupal\user\Plugin\views\field\Link::render_link().
*/
public
function
render_link
(
EntityInterface
$entity
,
\
stdClass
$values
)
{
if
(
$entity
&&
user_edit_access
(
$entity
))
{
$this
->
options
[
'alter'
][
'make_link'
]
=
TRUE
;
$text
=
!
empty
(
$this
->
options
[
'text'
])
?
$this
->
options
[
'text'
]
:
t
(
'edit'
);
$this
->
options
[
'alter'
][
'path'
]
=
"user/
$data
/edit"
;
$uri
=
$entity
->
uri
();
$this
->
options
[
'alter'
][
'path'
]
=
$uri
[
'path'
]
.
'/edit'
;
$this
->
options
[
'alter'
][
'query'
]
=
drupal_get_destination
();
return
$text
;
...
...
core/modules/user/lib/Drupal/user/Plugin/views/field/User.php
View file @
707c3d2f
...
...
@@ -53,9 +53,10 @@ public function buildOptionsForm(&$form, &$form_state) {
}
function
render_link
(
$data
,
$values
)
{
if
(
!
empty
(
$this
->
options
[
'link_to_user'
])
&&
user_access
(
'access user profiles'
)
&&
(
$
uid
=
$this
->
get_
value
(
$values
,
'uid'
))
&&
$data
!==
NULL
&&
$data
!==
''
)
{
if
(
!
empty
(
$this
->
options
[
'link_to_user'
])
&&
user_access
(
'access user profiles'
)
&&
(
$
entity
=
$this
->
get_
entity
(
$values
))
&&
$data
!==
NULL
&&
$data
!==
''
)
{
$this
->
options
[
'alter'
][
'make_link'
]
=
TRUE
;
$this
->
options
[
'alter'
][
'path'
]
=
"user/"
.
$uid
;
$uri
=
$entity
->
uri
();
$this
->
options
[
'alter'
][
'path'
]
=
$uri
[
'path'
];
}
return
$data
;
}
...
...
core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php
View file @
707c3d2f
...
...
@@ -355,12 +355,15 @@ function element_wrapper_classes($row_index = NULL) {
}
/**
* Get the entity matching the current row and relationship.
* Get
s
the entity matching the current row and relationship.
*
* @param $values
* @param
\stdClass
$values
* An object containing all retrieved values.
*
* @return \Drupal\Core\Entity\EntityInterface
* Returns the entity matching the values.
*/
function
get_entity
(
$values
)
{
public
function
get_entity
(
\
stdClass
$values
)
{
$relationship_id
=
$this
->
options
[
'relationship'
];
if
(
$relationship_id
==
'none'
)
{
return
$values
->
_entity
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment