Skip to content
Snippets Groups Projects
Commit cddbb5aa authored by Eric Bremner's avatar Eric Bremner Committed by Lily Yan
Browse files

ISTWCMS-6342: updating taxonomy terms to use UW landing pages

parent 80d0a497
No related branches found
No related tags found
1 merge request!365ISTWCMS-6342: updating taxonomy terms to use UW landing pages
...@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment