From 4034ca811e6f1bf9d336c778299cce1ed52b7ae4 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 29 Jun 2021 14:41:12 -0300 Subject: [PATCH] feat: add option `display_in_related_items` on relationship metadata type --- .../repositories/class-tainacan-items.php | 4 ++ .../class-tainacan-relationship.php | 47 +++++++++++++------ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 9327ab05b..0ed3a4e41 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -618,6 +618,10 @@ class Items extends Repository { [ 'key' => '_option_collection_id', 'value' => $current_collection->get_id() + ], + [ + 'key' => '_option_display_in_related_items', + 'value' => 'yes' ] ] ], 'OBJECT'); diff --git a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php index 07111ff90..0972e7e33 100644 --- a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php +++ b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php @@ -62,22 +62,26 @@ class Relationship extends Metadata_Type { 'repeated' => [ 'title' =>__( 'Allow repeated items', 'tainacan' ), 'description' => __( 'Allows different items to be related to the same item selected in another collection.', 'tainacan' ), + ], + 'display_in_related_items' => [ + 'title' =>__( 'Display in related items', 'tainacan' ), + 'description' => __( 'Include items on related item list.', 'tainacan' ), ] ]; } /** - * Gets print-ready version of the options list in html - * - * Checks if at least one option exists, otherwise return an empty string - * - * @return string An html content with labels and values for the options or an empty string - */ - public function get_options_as_html() { - $options_as_html = ''; - $options = $this->get_options(); + * Gets print-ready version of the options list in html + * + * Checks if at least one option exists, otherwise return an empty string + * + * @return string An html content with labels and values for the options or an empty string + */ + public function get_options_as_html() { + $options_as_html = ''; + $options = $this->get_options(); - if ( count($options) > 0 ) { + if ( count($options) > 0 ) { // Remove this option that is not relevant for the user if ( isset($options['related_primitive_type']) ) @@ -119,15 +123,24 @@ class Relationship extends Metadata_Type { $readable_option_value = $option_value; break; + case 'display_in_related_items': + if ($option_value == 'yes') + $readable_option_value = __('Yes', 'tainacan'); + else if ($option_value == 'no') + $readable_option_value = __('No', 'tainacan'); + else + $readable_option_value = $option_value; + break; + default: $readable_option_value = $option_value; } $options_as_html .= '
' . $readable_option_value . '
'; } - } - } - return $options_as_html; - } + } + } + return $options_as_html; + } public function validate_options(\Tainacan\Entities\Metadatum $metadatum) { if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) ) @@ -148,6 +161,12 @@ class Relationship extends Metadata_Type { 'search' => __('Search option must be a numeric Metadatum ID','tainacan') ]; } + // empty is ok + if ( !empty($this->get_option('display_in_related_items')) && !in_array($this->get_option('display_in_related_items'), ['yes', 'no']) ) { + return [ + 'search' => __('Display in related items must be a option yes or no','tainacan') + ]; + } return true; }