From 78c92237e1d2e667b5091ec7acb41d90d9b08633 Mon Sep 17 00:00:00 2001 From: nJim Date: Wed, 13 Sep 2023 10:52:52 -0400 Subject: [PATCH] fix (HOTFIX): reinstate changes from YALB-1518 lost in merge conflict resolution --- .../ys_views_basic/src/ViewsBasicManager.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php index 82c8f9cde9..31ae3c3ff1 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php @@ -169,14 +169,14 @@ public function getView($type, $params) { // Get terms to include. if (isset($paramsDecoded['filters']['terms_include'])) { foreach ($paramsDecoded['filters']['terms_include'] as $term) { - $termsIncludeArray[] = (int) is_object($term) ? $term['target_id'] : $term; + $termsIncludeArray[] = $this->getTermId($term); } } // Get terms to exclude. if (isset($paramsDecoded['filters']['terms_exclude'])) { foreach ($paramsDecoded['filters']['terms_exclude'] as $term) { - $termsExcludeArray[] = (int) is_object($term) ? $term['target_id'] : $term; + $termsExcludeArray[] = $this->getTermId($term); } } @@ -348,7 +348,7 @@ public function getDefaultParamValue($type, $params) { case 'terms_exclude': if (!empty($paramsDecoded['filters'][$type])) { foreach ($paramsDecoded['filters'][$type] as $term) { - $defaultParam[] = (int) $term; + $termsExcludeArray[] = $this->getTermId($term); } } break; @@ -428,4 +428,22 @@ public function getAllTags() : array { return $tagList; } + /** + * Returns an integer representation of the term. + * + * The term could be either the old Drupal way of an array with a + * target_id attribute containing a string representation of the id, or the + * chosen way of a string represenation of the id. This ensures that the + * decision of what should be return is handled here and not elsewhere. + * + * @param mixed $term + * The taxonomy term. + * + * @return int + * The term ID. + */ + private function getTermId($term) : int { + return (int) is_array($term) ? $term['target_id'] : $term; + } + }