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
26a0068b
Commit
26a0068b
authored
10 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2031901
by andypost: Remove node tokens from comment.tokens.inc.
parent
cd9b0f4f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/comment/comment.tokens.inc
+2
-31
2 additions, 31 deletions
core/modules/comment/comment.tokens.inc
core/modules/comment/src/Tests/CommentTokenReplaceTest.php
+5
-6
5 additions, 6 deletions
core/modules/comment/src/Tests/CommentTokenReplaceTest.php
with
7 additions
and
37 deletions
core/modules/comment/comment.tokens.inc
+
2
−
31
View file @
26a0068b
...
...
@@ -83,13 +83,6 @@ function comment_token_info() {
'description'
=>
t
(
"The entity the comment was posted to."
),
'type'
=>
'entity'
,
);
// Support legacy comment node tokens, since tokens are embedded in user data
// and can't be upgraded directly.
$comment
[
'node'
]
=
array
(
'name'
=>
t
(
"Node"
),
'description'
=>
t
(
"DEPRECATED: The node the comment was posted to."
),
'type'
=>
'node'
,
);
$comment
[
'author'
]
=
array
(
'name'
=>
t
(
"Author"
),
'description'
=>
t
(
"The author name of the comment."
),
...
...
@@ -101,8 +94,6 @@ function comment_token_info() {
'tokens'
=>
array
(
'entity'
=>
$entity
,
'comment'
=>
$comment
,
// Support deprecated node tokens.
'node'
=>
$entity
,
),
);
}
...
...
@@ -194,20 +185,6 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$title
=
$entity
->
label
();
$replacements
[
$original
]
=
$sanitize
?
Xss
::
filter
(
$title
)
:
$title
;
break
;
case
'node'
:
// Support legacy comment node tokens, since tokens are embedded in
// user data and can't be upgraded directly.
// @todo Remove in Drupal 9, see https://drupal.org/node/2031901.
if
(
$comment
->
getCommentedEntityTypeId
()
==
'node'
)
{
$entity
=
$comment
->
getCommentedEntity
();
$title
=
$entity
->
label
();
$replacements
[
$original
]
=
$sanitize
?
Xss
::
filter
(
$title
)
:
$title
;
}
else
{
$replacements
[
$original
]
=
NULL
;
}
break
;
}
}
...
...
@@ -217,11 +194,6 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$replacements
+=
$token_service
->
generate
(
$comment
->
getCommentedEntityTypeId
(),
$entity_tokens
,
array
(
$comment
->
getCommentedEntityTypeId
()
=>
$entity
),
$options
);
}
if
((
$node_tokens
=
$token_service
->
findwithPrefix
(
$tokens
,
'node'
))
&&
$comment
->
getCommentedEntityTypeId
()
==
'node'
)
{
$node
=
$comment
->
getCommentedEntity
();
$replacements
+=
$token_service
->
generate
(
'node'
,
$node_tokens
,
array
(
'node'
=>
$node
),
$options
);
}
if
(
$date_tokens
=
$token_service
->
findwithPrefix
(
$tokens
,
'created'
))
{
$replacements
+=
$token_service
->
generate
(
'date'
,
$date_tokens
,
array
(
'date'
=>
$comment
->
getCreatedTime
()),
$options
);
}
...
...
@@ -238,10 +210,9 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$replacements
+=
$token_service
->
generate
(
'user'
,
$author_tokens
,
array
(
'user'
=>
$account
),
$options
);
}
}
elseif
((
$type
==
'entity'
&
!
empty
(
$data
[
'entity'
]))
||
(
$type
==
'node'
&
!
empty
(
$data
[
'node'
])))
{
elseif
(
$type
==
'entity'
&
!
empty
(
$data
[
'entity'
]))
{
/** @var $entity \Drupal\Core\Entity\FieldableEntityInterface */
$entity
=
!
empty
(
$data
[
'entity'
]
)
?
$data
[
'entity'
]
:
$data
[
'node'
]
;
$entity
=
$data
[
'entity'
];
foreach
(
$tokens
as
$name
=>
$original
)
{
switch
(
$name
)
{
...
...
This diff is collapsed.
Click to expand it.
core/modules/comment/src/Tests/CommentTokenReplaceTest.php
+
5
−
6
View file @
26a0068b
...
...
@@ -63,8 +63,10 @@ function testCommentTokenReplacement() {
$tests
[
'[comment:changed:since]'
]
=
\Drupal
::
service
(
'date.formatter'
)
->
formatInterval
(
REQUEST_TIME
-
$comment
->
getChangedTime
(),
2
,
$language_interface
->
getId
());
$tests
[
'[comment:parent:cid]'
]
=
$comment
->
hasParentComment
()
?
$comment
->
getParentComment
()
->
id
()
:
NULL
;
$tests
[
'[comment:parent:title]'
]
=
String
::
checkPlain
(
$parent_comment
->
getSubject
());
$tests
[
'[comment:node:nid]'
]
=
$comment
->
getCommentedEntityId
();
$tests
[
'[comment:node:title]'
]
=
String
::
checkPlain
(
$node
->
getTitle
());
$tests
[
'[comment:entity]'
]
=
String
::
checkPlain
(
$node
->
getTitle
());
// Test node specific tokens.
$tests
[
'[comment:entity:nid]'
]
=
$comment
->
getCommentedEntityId
();
$tests
[
'[comment:entity:title]'
]
=
String
::
checkPlain
(
$node
->
getTitle
());
$tests
[
'[comment:author:uid]'
]
=
$comment
->
getOwnerId
();
$tests
[
'[comment:author:name]'
]
=
String
::
checkPlain
(
$this
->
admin_user
->
getUsername
());
...
...
@@ -84,7 +86,7 @@ function testCommentTokenReplacement() {
$tests
[
'[comment:title]'
]
=
$comment
->
getSubject
();
$tests
[
'[comment:body]'
]
=
$comment
->
comment_body
->
value
;
$tests
[
'[comment:parent:title]'
]
=
$parent_comment
->
getSubject
();
$tests
[
'[comment:n
ode:
tit
le
]'
]
=
$node
->
getTitle
();
$tests
[
'[comment:
e
ntit
y
]'
]
=
$node
->
getTitle
();
$tests
[
'[comment:author:name]'
]
=
$this
->
admin_user
->
getUsername
();
foreach
(
$tests
as
$input
=>
$expected
)
{
...
...
@@ -108,9 +110,6 @@ function testCommentTokenReplacement() {
$tests
=
array
();
$tests
[
'[entity:comment-count]'
]
=
2
;
$tests
[
'[entity:comment-count-new]'
]
=
2
;
// Also test the deprecated legacy token.
$tests
[
'[node:comment-count]'
]
=
2
;
$tests
[
'[node:comment-count-new]'
]
=
2
;
foreach
(
$tests
as
$input
=>
$expected
)
{
$output
=
$token_service
->
replace
(
$input
,
array
(
'entity'
=>
$node
,
'node'
=>
$node
),
array
(
'langcode'
=>
$language_interface
->
getId
()));
...
...
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