Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
node_keep
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
node_keep
Commits
63e61f48
Commit
63e61f48
authored
1 year ago
by
Stef De Waele
Committed by
Oleksandr Kuzava
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3339984
: Add node alias token
parent
f9f63ece
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Issue #3339984: Add node alias token
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
node_keep_token/node_keep_token.module
+22
-11
22 additions, 11 deletions
node_keep_token/node_keep_token.module
with
22 additions
and
11 deletions
node_keep_token/node_keep_token.module
+
22
−
11
View file @
63e61f48
...
...
@@ -140,18 +140,22 @@ function node_keep_token_token_info() {
$nodes
=
$keeper_helper
->
getProtectedNodes
();
foreach
(
$nodes
as
$data
)
{
$machine_name
=
$data
[
'machine_name'
];
$label
=
$data
[
'label'
];
$info
[
'tokens'
][
'node-keep'
][
$machine_name
.
':id'
]
=
[
'name'
=>
t
(
'@label
ID'
,
[
'@label'
=>
$label
]
),
'description'
=>
t
(
'
ID
of @label node.'
,
[
'@label'
=>
$label
]
),
$
t_args
=
[
'@
label
'
=
>
$data
[
'label'
]
]
;
$info
[
'tokens'
][
'node-keep'
][
"
{
$machine_name
}
:alias"
]
=
[
'name'
=>
t
(
'@label
alias'
,
$t_args
),
'description'
=>
t
(
'
Alias
of
"
@label
"
node.'
,
$t_args
),
];
$info
[
'tokens'
][
'node-keep'
][
$machine_name
.
':url'
]
=
[
'name'
=>
t
(
'@label
URL'
,
[
'@label'
=>
$label
]
),
'description'
=>
t
(
'
URL path
of @label node.'
,
[
'@label'
=>
$label
]
),
$info
[
'tokens'
][
'node-keep'
][
"
{
$machine_name
}
:id"
]
=
[
'name'
=>
t
(
'@label
ID'
,
$t_args
),
'description'
=>
t
(
'
ID
of
"
@label
"
node.'
,
$t_args
),
];
$info
[
'tokens'
][
'node-keep'
][
$machine_name
.
':uri'
]
=
[
'name'
=>
t
(
'@label URI'
,
[
'@label'
=>
$label
]),
'description'
=>
t
(
'URI of @label node.'
,
[
'@label'
=>
$label
]),
$info
[
'tokens'
][
'node-keep'
][
"
{
$machine_name
}
:url"
]
=
[
'name'
=>
t
(
'@label URL'
,
$t_args
),
'description'
=>
t
(
'URL path of "@label" node.'
,
$t_args
),
];
$info
[
'tokens'
][
'node-keep'
][
"
{
$machine_name
}
:uri"
]
=
[
'name'
=>
t
(
'@label URI'
,
$t_args
),
'description'
=>
t
(
'URI of "@label" node.'
,
$t_args
),
];
}
...
...
@@ -169,7 +173,14 @@ function node_keep_token_tokens($type, $tokens, array $data, array $options, Bub
$keeper_helper
=
\Drupal
::
service
(
'node_keep_token.helper'
);
$machine_names
=
$keeper_helper
->
getProtectedMachineNames
();
foreach
(
$tokens
as
$name
=>
$original
)
{
if
(
in_array
(
str_replace
(
':url'
,
''
,
$name
),
array_keys
(
$machine_names
)))
{
if
(
in_array
(
str_replace
(
':alias'
,
''
,
$name
),
array_keys
(
$machine_names
)))
{
/** @var \Drupal\path_alias\AliasManagerInterface $manager */
$manager
=
\Drupal
::
service
(
'path_alias.manager'
);
$base_name
=
str_replace
(
':alias'
,
''
,
$name
);
$nid
=
$machine_names
[
$base_name
][
'id'
];
$replacements
[
$original
]
=
$manager
->
getAliasByPath
(
"/node/
{
$nid
}
"
,
$options
[
'langcode'
]
??
NULL
);
}
elseif
(
in_array
(
str_replace
(
':url'
,
''
,
$name
),
array_keys
(
$machine_names
)))
{
$base_name
=
str_replace
(
':url'
,
''
,
$name
);
$nid
=
$machine_names
[
$base_name
][
'id'
];
$replacements
[
$original
]
=
Url
::
fromRoute
(
'entity.node.canonical'
,
[
'node'
=>
$nid
])
->
toString
();
...
...
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