diff --git a/uw_ct_service.module b/uw_ct_service.module index da42e64ffd64244735102099a32594b10f7a376a..07f8f40df7d176a4e7a005b80617032a290d92f6 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]); } } }