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

@ -487,9 +487,34 @@ class Item_Metadata_Entity extends Entity {
// if its required, at least one must be filled
$one_filled = false;
$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) {