Merge branch 'develop' into feature/compount-metadata-type-refactor

This commit is contained in:
vnmedeiros 2020-03-24 15:28:17 -03:00
commit 15d9025c20
1 changed files with 31 additions and 6 deletions

View File

@ -486,10 +486,35 @@ class Item_Metadata_Entity extends Entity {
// if its required, at least one must be filled
$one_filled = false;
$valid = true;
foreach($value as $val) {
if (!empty($val))
$one_filled = true;
$valid = true;
$dupe_array = array();
foreach($value as $val) {
if (!empty($val))
$one_filled = true;
if ($this->is_collection_key()) {
if (++$dupe_array[$val] > 1) {
$this->add_error( 'key_exists', sprintf( __('%s is a collection key and there is another item with the same value', 'tainacan'), $metadatum->get_name() ) );
return false;
}
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$test = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $this->metadatum->get_id(),
'value' => $val
]
],
'post__not_in' => [$item->get_id()]
], $item->get_collection());
if ($test->have_posts()) {
// translators: %s = metadatum name. ex: Register ID is a collection key and there is another item with the same value
$this->add_error( 'key_exists', sprintf( __('%s is a collection key and there is another item with the same value', 'tainacan'), $metadatum->get_name() ) );
return false;
}
}
}
if ($this->is_required() && !$one_filled) {
@ -505,7 +530,7 @@ class Item_Metadata_Entity extends Entity {
}
$this->set_as_valid();
return true;
return true;
} else {
// translators: %s = metadatum name. ex: Title is invalid
$this->add_error( 'invalid', sprintf( __('%s is invalid', 'tainacan'), $metadatum->get_name() ) );
@ -540,7 +565,7 @@ class Item_Metadata_Entity extends Entity {
}
$this->set_as_valid();
return true;
return true;
}
}
}