Skip to content

Commit

Permalink
fix (HOTFIX): reinstate changes from YALB-1518 lost in merge conflict…
Browse files Browse the repository at this point in the history
… resolution
  • Loading branch information
nJim committed Sep 13, 2023
1 parent 7c20b32 commit 78c9223
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 78c9223

Please sign in to comment.