bootstraps for taxonomy html test

This commit is contained in:
Rodrigo de Oliveira 2021-04-06 08:40:05 -03:00
parent d4b67beb30
commit 7e7c36d60b
4 changed files with 28 additions and 21 deletions

View File

@ -500,26 +500,20 @@ class Item extends Entity {
public function _toHtml() { public function _toHtml() {
$return = ''; $return = '';
$id = $this->get_id(); $id = $this->get_id();
if ( $id ) { if ( $id ) {
$link = get_permalink( (int) $id ); $link = get_permalink( (int) $id );
if (is_string($link)) { if (is_string($link)) {
$return = "<a data-linkto='item' data-id='$id' href='$link'>"; $return = "<a data-linkto='item' data-id='$id' href='$link'>";
$return.= $this->get_title(); $return.= $this->get_title();
$return .= "</a>"; $return .= "</a>";
} }
} }
return $return; return $return;
} }
/** /**

View File

@ -245,25 +245,19 @@ class Term extends Entity {
} }
public function _toHtml() { public function _toHtml() {
$return = ''; $return = '';
$id = $this->get_id(); $id = $this->get_id();
if ( $id ) { if ( $id ) {
$link = get_term_link( (int) $id ); $link = get_term_link( (int) $id );
if (is_string($link)) { if (is_string($link)) {
$return = "<a data-linkto='term' data-id='$id' href='$link'>"; $return = "<a data-linkto='term' data-id='$id' href='$link'>";
$return.= $this->get_name(); $return.= $this->get_name();
$return .= "</a>"; $return .= "</a>";
} }
} }
return apply_filters('tainacan-term-to-html', $return, $this); return apply_filters('tainacan-term-to-html', $return, $this);
} }
} }

View File

@ -332,9 +332,7 @@ class Taxonomy extends Metadata_Type {
* @return string The HTML representation of the value, containing one or multiple terms, separated by comma, linked to term page * @return string The HTML representation of the value, containing one or multiple terms, separated by comma, linked to term page
*/ */
public function get_value_as_html(Item_Metadata_Entity $item_metadata) { public function get_value_as_html(Item_Metadata_Entity $item_metadata) {
$value = $item_metadata->get_value(); $value = $item_metadata->get_value();
$return = ''; $return = '';
if ( $item_metadata->is_multiple() ) { if ( $item_metadata->is_multiple() ) {
@ -345,7 +343,7 @@ class Taxonomy extends Metadata_Type {
$separator = $item_metadata->get_multivalue_separator(); $separator = $item_metadata->get_multivalue_separator();
foreach ( $value as $term ) { foreach ( $value as $term ) {
$count ++; $count++;
if ( is_integer($term) ) { if ( is_integer($term) ) {
$term = \Tainacan\Repositories\Terms::get_instance()->fetch($term, $this->get_option('taxonomy_id')); $term = \Tainacan\Repositories\Terms::get_instance()->fetch($term, $this->get_option('taxonomy_id'));
@ -361,7 +359,6 @@ class Taxonomy extends Metadata_Type {
} }
} }
} }
} else { } else {
if ( $value instanceof \Tainacan\Entities\Term ) { if ( $value instanceof \Tainacan\Entities\Term ) {
$return .= $this->get_term_hierarchy_html($value); $return .= $this->get_term_hierarchy_html($value);
@ -372,9 +369,7 @@ class Taxonomy extends Metadata_Type {
} }
private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) {
$terms = []; $terms = [];
$terms[] = $this->term_to_html($term); $terms[] = $this->term_to_html($term);
while ($term->get_parent() > 0) { while ($term->get_parent() > 0) {
@ -383,11 +378,9 @@ class Taxonomy extends Metadata_Type {
} }
$terms = \array_reverse($terms); $terms = \array_reverse($terms);
$glue = apply_filters('tainacan-terms-hierarchy-html-separator', '<span class="hierarchy-separator"> > </span>'); $glue = apply_filters('tainacan-terms-hierarchy-html-separator', '<span class="hierarchy-separator"> > </span>');
return \implode($glue, $terms); return \implode($glue, $terms);
} }
private function term_to_html($term) { private function term_to_html($term) {

View File

@ -659,4 +659,30 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
return "<a data-linkto='item' data-id='${id}' href='${URL}'>${title}</a>"; return "<a data-linkto='item' data-id='${id}' href='${URL}'>${title}</a>";
} }
function test_taxonomy_metadata_html() {
$taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'My Taxonomy test',
'collections' => [$this->collection],
'status' => 'publish'
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'My tax meta',
'status' => 'publish',
'collection' => $this->collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [
'taxonomy_id' => $taxonomy->get_id(),
]
),
true
);
}
} }