Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drupal Upstream
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
ASC IRIS Web Services
Drupal Upstream
Commits
4f3888a2
Commit
4f3888a2
authored
5 years ago
by
Brian Canini
Browse files
Options
Downloads
Patches
Plain Diff
new custom module
customtokens - adds custom token for research url alias
parent
f04b9141
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
web/modules/custom/customtokens/customtokens.info.yml
+5
-0
5 additions, 0 deletions
web/modules/custom/customtokens/customtokens.info.yml
web/modules/custom/customtokens/customtokens.module
+40
-0
40 additions, 0 deletions
web/modules/custom/customtokens/customtokens.module
with
45 additions
and
0 deletions
web/modules/custom/customtokens/customtokens.info.yml
0 → 100644
+
5
−
0
View file @
4f3888a2
name
:
Custom Tokens
description
:
'
Creates
custom
tokens'
core
:
8.x
type
:
module
package
:
ASC Tech
This diff is collapsed.
Click to expand it.
web/modules/custom/customtokens/customtokens.module
0 → 100644
+
40
−
0
View file @
4f3888a2
<?php
/**
* Implements hook_token_info().
*/
function
customtokens_token_info
()
{
$type
=
[
'name'
=>
t
(
'Custom Token'
),
'description'
=>
t
(
'Tokens for custom things.'
),
];
$node
[
'landingct'
]
=
[
'name'
=>
t
(
"Research Landing Page"
),
'description'
=>
t
(
'The node\'s Research Landing Page'
),
];
return
[
'types'
=>
[
'customtoken'
=>
$type
],
'tokens'
=>
[
'customtoken'
=>
$node
],
];
}
/**
* Implements hook_tokens().
*/
function
customtokens_tokens
(
$type
,
$tokens
,
array
$data
,
array
$options
,
\Drupal\Core\Render\BubbleableMetadata
$bubbleable_metadata
)
{
$replacements
=
[];
$nids
=
\Drupal
::
entityQuery
(
'node'
)
->
condition
(
'type'
,
'research_landing_page'
)
->
execute
();
$nodes
=
\Drupal\node\Entity\Node
::
loadMultiple
(
$nids
);
$lid
=
array_shift
(
array_keys
(
$nodes
));
$alias
=
\Drupal
::
service
(
'path.alias_manager'
)
->
getAliasByPath
(
'/node/'
.
$lid
);
if
(
$type
==
'customtoken'
&&
!
empty
(
$data
[
'node'
]))
{
foreach
(
$tokens
as
$name
=>
$original
)
{
switch
(
$name
)
{
case
'landingct'
:
$replacements
[
$original
]
=
$alias
;
break
;
}
}
}
return
$replacements
;
}
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