From 5ed051103e431d5c790303181ca5a35a4c7dc2ed Mon Sep 17 00:00:00 2001 From: leogermani Date: Mon, 29 Jul 2019 11:40:29 -0300 Subject: [PATCH] Display full hierarchy for taxonomy metadata #283 --- .../taxonomy/class-tainacan-taxonomy.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php index a01bff51a..51d828fcc 100644 --- a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -220,7 +220,7 @@ class Taxonomy extends Metadata_Type { if ( $term instanceof \Tainacan\Entities\Term ) { $return .= $prefix; - $return .= $term->_toHtml(); + $return .= $this->get_term_hierarchy_html($term); $return .= $suffix; @@ -244,6 +244,23 @@ class Taxonomy extends Metadata_Type { } + private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { + + $terms = []; + + $terms[] = $term->_toHtml(); + + while ($term->get_parent() > 0) { + $term = \Tainacan\Repositories\Terms::get_instance()->fetch( (int) $term->get_parent(), $term->get_taxonomy() ); + $terms[] = $term->_toHtml(); + } + + $terms = \array_reverse($terms); + + return \implode(' > ', $terms); + + } + public function _toArray() { $array = parent::_toArray();