Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
cddbb5aa
Commit
cddbb5aa
authored
1 year ago
by
Eric Bremner
Committed by
Lily Yan
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-6342: updating taxonomy terms to use UW landing pages
parent
80d0a497
No related branches found
No related tags found
1 merge request
!365
ISTWCMS-6342: updating taxonomy terms to use UW landing pages
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Service/UwNodeFieldValue.php
+60
-2
60 additions, 2 deletions
src/Service/UwNodeFieldValue.php
with
60 additions
and
2 deletions
src/Service/UwNodeFieldValue.php
+
60
−
2
View file @
cddbb5aa
...
@@ -699,9 +699,59 @@ class UwNodeFieldValue {
...
@@ -699,9 +699,59 @@ class UwNodeFieldValue {
// Need empty array in case there are no terms.
// Need empty array in case there are no terms.
$tags
=
[];
$tags
=
[];
// The list of content types and their listing page url.
$content_type_list
=
[
'uw_ct_blog'
=>
'blog'
,
'uw_ct_event'
=>
'events'
,
'uw_ct_news_item'
=>
'news'
,
'uw_ct_opportunity'
=>
'opportunities'
,
];
// Get the content type name.
$content_type
=
$node
->
getType
();
// Step through each of the terms and add to array.
// Step through each of the terms and add to array.
foreach
(
$field_name
as
$field
)
{
foreach
(
$field_name
as
$field
)
{
$tags
=
array_merge
(
$tags
,
$this
->
getTermsFromEntityField
(
$node
->
$field
,
'tags'
));
$tags
=
array_merge
(
$tags
,
$this
->
getTermsFromEntityField
(
$node
->
$field
,
'tags'
,
$field
));
}
// If the content type is in the list to convert,
// then perform the url conversion.
if
(
array_key_exists
(
$content_type
,
$content_type_list
))
{
// The tag field names to use in the parameters.
$tag_field_names
=
[
'field_uw_audience'
=>
'audience'
,
'field_uw_event_type'
=>
'type'
,
'field_uw_opportunity_type'
=>
'opportunity_type'
,
'field_uw_opportunity_employment'
=>
'employment_type'
,
'field_uw_opportunity_pay_type'
=>
'rate_of_pay'
,
];
// Step through each of the tags and get the
// correct url.
foreach
(
$tags
as
$index
=>
$tag
)
{
// Start the url to the content type listing page.
$new_url
=
'/'
.
$content_type_list
[
$content_type
];
$new_url
.
=
'?'
;
// If the tag is in the list of field names to convert,
// then convert them using the url provided, if not use
// the field name with tags.
if
(
array_key_exists
(
$tag
[
'field_name'
],
$tag_field_names
))
{
$new_url
.
=
$tag_field_names
[
$tag
[
'field_name'
]];
}
else
{
$new_url
.
=
'tags'
;
}
// Add the tid to the new url.
$new_url
.
=
'['
.
$tag
[
'tid'
]
.
']='
.
$tag
[
'tid'
];
// Set the new url.
$tags
[
$index
][
'url'
]
=
$new_url
;
}
}
}
// Return array of terms.
// Return array of terms.
...
@@ -855,13 +905,19 @@ class UwNodeFieldValue {
...
@@ -855,13 +905,19 @@ class UwNodeFieldValue {
* List of values for the provided field.
* List of values for the provided field.
* @param string|null $type
* @param string|null $type
* The type of terms to get, if none provided just term name returned.
* The type of terms to get, if none provided just term name returned.
* @param string|null $field_name
* The name of the field.
*
*
* @return array
* @return array
* List of terms with name and link.
* List of terms with name and link.
*
*
* @throws \Drupal\Core\Entity\EntityMalformedException
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
*/
public
function
getTermsFromEntityField
(
EntityReferenceFieldItemListInterface
$values
,
string
$type
=
NULL
):
array
{
public
function
getTermsFromEntityField
(
EntityReferenceFieldItemListInterface
$values
,
string
$type
=
NULL
,
string
$field_name
=
NULL
):
array
{
// Array to hold the terms, need to set to
// Array to hold the terms, need to set to
// null in case there are no terms to be
// null in case there are no terms to be
...
@@ -907,6 +963,8 @@ class UwNodeFieldValue {
...
@@ -907,6 +963,8 @@ class UwNodeFieldValue {
$terms
[]
=
[
$terms
[]
=
[
'title'
=>
$term_entity
->
getName
(),
'title'
=>
$term_entity
->
getName
(),
'url'
=>
$url
,
'url'
=>
$url
,
'tid'
=>
$term_entity
->
id
(),
'field_name'
=>
$field_name
,
];
];
}
}
else
{
else
{
...
...
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