From 55afa4567c0431945b4d8a898d1aecd6de4949a8 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sun, 4 Apr 2021 23:31:32 -0300 Subject: [PATCH] Refactors HTML return for date meta --- .../class-tainacan-item-metadata-entity.php | 9 ++------- .../metadata-types/date/class-tainacan-date.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 4fb83faa4..8b215f01d 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -136,17 +136,15 @@ class Item_Metadata_Entity extends Entity { * Get the value as a HTML string, with markup and links * @return string */ - public function get_value_as_html(){ + public function get_value_as_html(){ $metadatum = $this->get_metadatum(); if (is_object($metadatum)) { $fto = $metadatum->get_metadata_type_object(); if (is_object($fto)) { - if ( method_exists($fto, 'get_value_as_html') ) { return $fto->get_value_as_html($this); } - } } @@ -163,7 +161,6 @@ class Item_Metadata_Entity extends Entity { $separator = $this->get_multivalue_separator(); foreach ($value as $v) { - $return .= $prefix; $return .= (string) $v; @@ -174,14 +171,12 @@ class Item_Metadata_Entity extends Entity { if ($count < $total) $return .= $separator; } - + } else { $return = (string) $value; } return $return; - - } /** diff --git a/src/views/admin/components/metadata-types/date/class-tainacan-date.php b/src/views/admin/components/metadata-types/date/class-tainacan-date.php index a17d883de..767a34ee3 100644 --- a/src/views/admin/components/metadata-types/date/class-tainacan-date.php +++ b/src/views/admin/components/metadata-types/date/class-tainacan-date.php @@ -80,20 +80,23 @@ class Date extends Metadata_Type { if( empty( $el ) ) continue; $return .= $prefix; - $return .= mysql2date(get_option('date_format'), ($el)); + $return .= $this->format_date_value($el); $return .= $suffix; $count ++; if ($count < $total) $return .= $separator; } } else { - if( empty( $value ) ) - return ""; - $return = mysql2date(get_option('date_format'), ($value)); + + $return = $this->format_date_value($value); } return $return; - } + private function format_date_value($value) { + if (empty($value)) + return ""; + return mysql2date(get_option('date_format'), ($value)); + } } \ No newline at end of file