Creates link filtered by current collection option to taxonomy form. #904.

This commit is contained in:
mateuswetah 2024-07-03 12:08:46 -03:00
parent 6f8989637a
commit a58f4bb140
3 changed files with 34 additions and 9 deletions

View File

@ -113,6 +113,21 @@
:title="$i18n.getHelperTitle('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" :title="$i18n.getHelperTitle('tainacan-taxonomy', 'do_not_dispaly_term_as_link')"
:message="$i18n.getHelperMessage('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" /> :message="$i18n.getHelperMessage('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" />
</b-field> </b-field>
<b-field
:addons="false"
:label="$i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_current_collection')">
&nbsp;
<b-switch
v-model="link_filtered_by_current_collection"
size="is-small"
:disabled="do_not_dispaly_term_as_link == 'yes'"
true-value="yes"
false-value="no"
@update:model-value="emitValues()" />
<help-button
:title="$i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_current_collection')"
:message="$i18n.getHelperMessage('tainacan-taxonomy', 'link_filtered_by_current_collection')" />
</b-field>
<b-field :addons="false"> <b-field :addons="false">
<label class="label"> <label class="label">
{{ $i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_collections') }} {{ $i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_collections') }}
@ -127,7 +142,7 @@
:data="collections.filter((collection) => !link_filtered_by_collections.includes(collection.id) && (collectionSearchString ? (collection.name.toLowerCase().indexOf(collectionSearchString.toLowerCase()) >= 0) : true) )" :data="collections.filter((collection) => !link_filtered_by_collections.includes(collection.id) && (collectionSearchString ? (collection.name.toLowerCase().indexOf(collectionSearchString.toLowerCase()) >= 0) : true) )"
field="name" field="name"
attached attached
:disabled="do_not_dispaly_term_as_link == 'yes'" :disabled="link_filtered_by_current_collection === 'yes' || do_not_dispaly_term_as_link == 'yes'"
:remove-on-keys="[]" :remove-on-keys="[]"
:aria-close-label="$i18n.get('remove_value')" :aria-close-label="$i18n.get('remove_value')"
:class="{'has-selected': link_filtered_by_collections != undefined && link_filtered_by_collections != []}" :class="{'has-selected': link_filtered_by_collections != undefined && link_filtered_by_collections != []}"
@ -194,6 +209,7 @@
allow_new_terms: 'yes', allow_new_terms: 'yes',
hide_hierarchy_path: 'no', hide_hierarchy_path: 'no',
do_not_dispaly_term_as_link: 'no', do_not_dispaly_term_as_link: 'no',
link_filtered_by_current_collection: 'no',
link_filtered_by_collections: [], link_filtered_by_collections: [],
visible_options_list: false, visible_options_list: false,
input_type: 'tainacan-taxonomy-radio', input_type: 'tainacan-taxonomy-radio',
@ -265,6 +281,7 @@
this.taxonomy_id = this.value.taxonomy_id; this.taxonomy_id = this.value.taxonomy_id;
this.allow_new_terms = ( this.value.allow_new_terms ) ? this.value.allow_new_terms : 'no'; this.allow_new_terms = ( this.value.allow_new_terms ) ? this.value.allow_new_terms : 'no';
this.hide_hierarchy_path = ( this.value.hide_hierarchy_path ) ? this.value.hide_hierarchy_path : 'no'; this.hide_hierarchy_path = ( this.value.hide_hierarchy_path ) ? this.value.hide_hierarchy_path : 'no';
this.link_filtered_by_current_collection = ( this.value.link_filtered_by_current_collection ) ? this.value.link_filtered_by_current_collection : 'no';
this.do_not_dispaly_term_as_link = ( this.value.do_not_dispaly_term_as_link ) ? this.value.do_not_dispaly_term_as_link : 'no'; this.do_not_dispaly_term_as_link = ( this.value.do_not_dispaly_term_as_link ) ? this.value.do_not_dispaly_term_as_link : 'no';
if (this.metadatum && this.metadatum.multiple === 'no') { if (this.metadatum && this.metadatum.multiple === 'no') {
@ -331,6 +348,7 @@
input_type: this.input_type, input_type: this.input_type,
allow_new_terms: this.allow_new_terms, allow_new_terms: this.allow_new_terms,
visible_options_list: this.visible_options_list, visible_options_list: this.visible_options_list,
link_filtered_by_current_collection: this.link_filtered_by_current_collection,
link_filtered_by_collections: this.link_filtered_by_collections, link_filtered_by_collections: this.link_filtered_by_collections,
hide_hierarchy_path: this.hide_hierarchy_path, hide_hierarchy_path: this.hide_hierarchy_path,
do_not_dispaly_term_as_link: this.do_not_dispaly_term_as_link, do_not_dispaly_term_as_link: this.do_not_dispaly_term_as_link,

View File

@ -21,6 +21,7 @@ class Taxonomy extends Metadata_Type {
$this->set_default_options([ $this->set_default_options([
'allow_new_terms' => 'no', 'allow_new_terms' => 'no',
'link_filtered_by_current_collection' => 'no',
'link_filtered_by_collections' => [], 'link_filtered_by_collections' => [],
'input_type' => 'tainacan-taxonomy-radio', 'input_type' => 'tainacan-taxonomy-radio',
'hide_hierarchy_path' => 'no', 'hide_hierarchy_path' => 'no',
@ -100,6 +101,10 @@ class Taxonomy extends Metadata_Type {
'title' => __( 'Allow new terms', 'tainacan' ), 'title' => __( 'Allow new terms', 'tainacan' ),
'description' => __( 'Allows to create new terms directly on the item form.', 'tainacan' ), 'description' => __( 'Allows to create new terms directly on the item form.', 'tainacan' ),
], ],
'link_filtered_by_current_collection' => [
'title' => __( 'Link filtered by current collection', 'tainacan' ),
'description' => __( 'Links to term items list filtered by the collection of the current item instead of a repository level term items page.', 'tainacan' ),
],
'link_filtered_by_collections' => [ 'link_filtered_by_collections' => [
'title' => __( 'Link filtered by collections', 'tainacan' ), 'title' => __( 'Link filtered by collections', 'tainacan' ),
'description' => __( 'Links to term items list filtered by certain collections instead of repository level term items page.', 'tainacan' ), 'description' => __( 'Links to term items list filtered by certain collections instead of repository level term items page.', 'tainacan' ),
@ -173,6 +178,7 @@ class Taxonomy extends Metadata_Type {
case 'allow_new_terms': case 'allow_new_terms':
case 'do_not_dispaly_term_as_link': case 'do_not_dispaly_term_as_link':
case 'link_filtered_by_current_collection':
if ($option_value == 'yes') if ($option_value == 'yes')
$readable_option_value = __('Yes', 'tainacan'); $readable_option_value = __('Yes', 'tainacan');
else if ($option_value == 'no') else if ($option_value == 'no')
@ -374,7 +380,7 @@ class Taxonomy extends Metadata_Type {
if ( $term instanceof \Tainacan\Entities\Term ) { if ( $term instanceof \Tainacan\Entities\Term ) {
$return .= $prefix; $return .= $prefix;
$return .= $this->get_term_hierarchy_html($term); $return .= $this->get_term_hierarchy_html($term, $item_metadata->get_item());
$return .= $suffix; $return .= $suffix;
if ( $count <= $total ) { if ( $count <= $total ) {
@ -384,24 +390,24 @@ 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, $item_metadata->get_item());
} }
} }
return $return; return $return;
} }
private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { private function get_term_hierarchy_html( \Tainacan\Entities\Term $term, \Tainacan\Entities\Item $item = null) {
if ( $this->get_option('hide_hierarchy_path') == 'yes' ) if ( $this->get_option('hide_hierarchy_path') == 'yes' )
return $this->term_to_html($term); return $this->term_to_html($term, $item);
$terms = []; $terms = [];
$terms[] = $this->term_to_html($term); $terms[] = $this->term_to_html($term, $item);
while ($term->get_parent() > 0) { while ($term->get_parent() > 0) {
$term = \Tainacan\Repositories\Terms::get_instance()->fetch( (int) $term->get_parent(), $term->get_taxonomy() ); $term = \Tainacan\Repositories\Terms::get_instance()->fetch( (int) $term->get_parent(), $term->get_taxonomy() );
$terms[] = $this->term_to_html($term); $terms[] = $this->term_to_html($term, $item);
} }
$terms = \array_reverse($terms); $terms = \array_reverse($terms);
@ -410,8 +416,8 @@ class Taxonomy extends Metadata_Type {
return \implode($glue, $terms); return \implode($glue, $terms);
} }
private function term_to_html($term) { private function term_to_html($term, \Tainacan\Entities\Item $item = null) {
$collections = $this->get_option( 'link_filtered_by_collections' ); $collections = ( isset($item) && $this->get_option( 'link_filtered_by_current_collection' ) === 'yes' ) ? [ $item->get_collection_id() ] : $this->get_option( 'link_filtered_by_collections' );
$do_not_display_term_as_link = $this->get_option('do_not_dispaly_term_as_link') == 'yes'; $do_not_display_term_as_link = $this->get_option('do_not_dispaly_term_as_link') == 'yes';
if ( !empty( $collections ) ) { if ( !empty( $collections ) ) {

View File

@ -643,6 +643,7 @@ class Taxonomies extends TAINACAN_UnitTestCase {
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => 'no', 'allow_new_terms' => 'no',
'link_filtered_by_current_collection' => 'no',
'link_filtered_by_collections' => [$collectionOnly->get_id()] 'link_filtered_by_collections' => [$collectionOnly->get_id()]
] ]
), ),