From 9d8fb3969465f21505f7f2952e13ca97b867d65e Mon Sep 17 00:00:00 2001 From: Lily Yan <l26yan@uwaterloo.ca> Date: Wed, 21 Feb 2024 13:57:29 -0500 Subject: [PATCH] ISTWCMS-6768 Add code to make sure parent level service category works --- uw_ct_service.module | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/uw_ct_service.module b/uw_ct_service.module index da42e64..07f8f40 100644 --- a/uw_ct_service.module +++ b/uw_ct_service.module @@ -215,8 +215,22 @@ function uw_ct_service_views_query_alter( $load_entities = FALSE; $child_terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid, $parent_tid, $depth, $load_entities); - if (!empty($child_terms)) { - $query->where[1]['conditions'][2]['value'] = 2; + // Services category view is based on nested service categories. + // If passing taxonomy term doesn't include child terms, we should + // remove relationship via service category field and related to it. + if (empty($child_terms)) { + unset($query->fields['node__field_uw_service_category_delta']); + unset($query->fields['node__field_uw_service_category_field_uw_service_category_ta']); + unset($query->fields['taxonomy_term_field_data_node__field_uw_service_category_dep']); + unset($query->fields['taxonomy_term_field_data_node__field_uw_service_category_wei']); + unset($view->storage->getDisplay('services_in_category_page')['display_options']['fields']['field_uw_service_category']); + unset($view->storage->getDisplay('services_in_category_page')['display_options']['style']['options']['grouping'][0]); + unset($view->storage->getDisplay('services_in_category_page')['display_options']['relationships']); + unset($view->storage->getDisplay('services_in_category_page')['display_options']['sorts']['depth_level']); + unset($view->storage->getDisplay('services_in_category_page')['display_options']['sorts']['weight']); + unset($query->where[1]['conditions'][2]); + unset($query->orderby[0]); + unset($query->orderby[1]); } } } -- GitLab