Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
message_plus
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
message_plus
Merge requests
!3
Issue
#3432347
: Add tokens for reference fields
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3432347
: Add tokens for reference fields
issue/message_plus-3432347:3432347-add-tokens-for
into
1.0.x
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
igor mashevskyi
requested to merge
issue/message_plus-3432347:3432347-add-tokens-for
into
1.0.x
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#3432347
0
0
Merge request reports
Compare
1.0.x
1.0.x (base)
and
latest version
latest version
e82a6623
1 commit,
1 year ago
1 file
+
21
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
message_plus.tokens.inc
+
21
−
2
Options
@@ -5,6 +5,7 @@
* Provides Token integration for Message Plus.
*/
use
Drupal\Core\Render\BubbleableMetadata
;
use
Drupal\message\MessageInterface
;
/**
@@ -48,7 +49,8 @@ function message_plus_token_info() {
/**
* Implements hook_tokens().
*/
function
message_plus_tokens
(
$type
,
$tokens
,
array
$data
)
{
function
message_plus_tokens
(
$type
,
$tokens
,
array
$data
,
array
$options
,
BubbleableMetadata
$bubbleable_metadata
)
{
$token_service
=
\Drupal
::
token
();
$replacements
=
[];
if
(
$type
!=
'message'
||
!
(
$message
=
$data
[
'message'
]
??
NULL
)
instanceof
MessageInterface
)
{
@@ -61,7 +63,24 @@ function message_plus_tokens($type, $tokens, array $data) {
continue
;
}
foreach
([
'_name'
,
'_link'
]
as
$string_ending
)
{
// Process reference field tokens.
$matches
=
[];
preg_match
(
'/(?<=field_)(.*)(?=_reference)/'
,
$name
,
$matches
);
$entity_type_id
=
$matches
[
0
]
??
NULL
;
if
(
$entity_type_id
&&
(
$field_name
=
'field_'
.
$entity_type_id
.
'_reference'
)
&&
$message
->
hasField
(
$field_name
)
&&
$entity_tokens
=
$token_service
->
findWithPrefix
(
$tokens
,
$field_name
)
)
{
$replacements
+=
$token_service
->
generate
(
$entity_type_id
,
$entity_tokens
,
[
$entity_type_id
=>
$message
->
get
(
$field_name
)
->
entity
,
],
$options
,
$bubbleable_metadata
);
}
// Process reference field name and link.
foreach
([
'name'
,
'link'
]
as
$string_ending
)
{
if
(
!
str_ends_with
(
$name
,
$string_ending
))
{
continue
;
}
Loading