Skip to content

Commit

Permalink
refactor: replace static Term helper calls with Term class instances (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink authored Jan 9, 2025
1 parent 8902957 commit e17d4d4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
14 changes: 12 additions & 2 deletions library/Controller/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ public function getCurrentTermColour()
return false;
}

return \Municipio\Helper\Term::getTermColor($term->term_id, $term->taxonomy);
$termHelper = new \Municipio\Helper\Term\Term(
\Municipio\Helper\WpService::get(),
\Municipio\Helper\AcfService::get()
);

return $termHelper->getTermColor($term->term_id, $term->taxonomy);
}

/**
Expand All @@ -144,7 +149,12 @@ public function getCurrentTermIcon()
return false;
}

return \Municipio\Helper\Term::getTermIcon($term->term_id, $term->taxonomy);
$termHelper = new \Municipio\Helper\Term\Term(
\Municipio\Helper\WpService::get(),
\Municipio\Helper\AcfService::get()
);

return $termHelper->getTermIcon($term->term_id, $term->taxonomy);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion library/Helper/Listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public static function getTermsWithIcon(array $termIds = [])
if (!$term || is_wp_error($term)) {
continue;
}
$term->icon = \Municipio\Helper\Term::getTermIcon($term);

$termHelper = new \Municipio\Helper\Term\Term(
\Municipio\Helper\WpService::get(),
\Municipio\Helper\AcfService::get()
);

$term->icon = $termHelper->getTermIcon($term);
$terms[] = $term;
}
return $terms;
Expand Down
9 changes: 5 additions & 4 deletions library/Helper/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,17 @@ private static function getPostExcerpt($postObject): array
private static function getPostTermIcon($postId, $postType)
{
$taxonomies = get_object_taxonomies($postType);
$termIcon = [];
$termColor = false;
$termHelper = new \Municipio\Helper\Term\Term(\Municipio\Helper\WpService::get(), \Municipio\Helper\AcfService::get());

$termIcon = [];
$termColor = false;
foreach ($taxonomies as $taxonomy) {
$terms = get_the_terms($postId, $taxonomy);
if (!empty($terms)) {
foreach ($terms as $term) {
if (empty($termIcon)) {
$icon = \Municipio\Helper\Term::getTermIcon($term, $taxonomy);
$color = \Municipio\Helper\Term::getTermColor($term, $taxonomy);
$icon = $termHelper->getTermIcon($term, $taxonomy);
$color = $termHelper->getTermColor($term, $taxonomy);
if (!empty($icon) && !empty($icon['src']) && $icon['type'] == 'icon') {
$termIcon['icon'] = $icon['src'];
$termIcon['size'] = 'md';
Expand Down
9 changes: 7 additions & 2 deletions library/PostObject/TermIcon/TryGetTermIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class TryGetTermIcon implements TryGetTermIconInterface
*/
public function tryGetTermIcon(int $termId, string $taxonomy): ?TermIconInterface
{
$icon = \Municipio\Helper\Term::getTermIcon($termId, $taxonomy);
$color = \Municipio\Helper\Term::getTermColor($termId, $taxonomy);
$termHelper = new \Municipio\Helper\Term\Term(
\Municipio\Helper\WpService::get(),
\Municipio\Helper\AcfService::get()
);

$icon = $termHelper->getTermIcon($termId, $taxonomy);
$color = $termHelper->getTermColor($termId, $taxonomy);

if (!empty($icon) && !empty($icon['src']) && $icon['type'] == 'icon') {
return $this->createTermIcon($termId, $icon['src'], $color);
Expand Down

0 comments on commit e17d4d4

Please sign in to comment.