relationship value_to_html()

This commit is contained in:
Leo Germani 2018-04-09 18:55:40 -03:00
parent 333a12001b
commit aab19010a1
2 changed files with 74 additions and 0 deletions

View File

@ -409,4 +409,29 @@ class Item extends Entity {
return parent::validate();
}
public function __toHtml() {
$return = '';
$id = $this->get_id();
if ( $id ) {
$link = get_permalink( (int) $id );
if (is_string($link)) {
$return = "<a data-linkto='item' data-id='$id' href='$link'>";
$return.= $this->get_title();
$return .= "</a>";
}
}
return $return;
}
}

View File

@ -66,4 +66,53 @@ class Relationship extends Field_Type {
}
return true;
}
public function __value_to_html(Item_Metadata_Entity $item_metadata) {
$value = $item_metadata->get_value();
$return = '';
if ( $item_metadata->is_multiple() ) {
$count = 1;
$total = sizeof($value);
foreach ( $value as $item_id ) {
try {
$item = new \Tainacan\Entities\Item($item_id);
if ( $item instanceof \Tainacan\Entities\Item ) {
$return .= $item->__toHtml();
}
$count ++;
if ( $count <= $total ) {
$return .= ', ';
}
} catch (Exception $e) {
// item not found
}
}
} else {
if ( $value instanceof \Tainacan\Entities\Item ) {
$return .= $value->__toHtml();
}
}
return $return;
}
}