Merge branch 'develop' into feature/compount-metadata-type-refactor
This commit is contained in:
commit
15d9025c20
|
@ -486,10 +486,35 @@ class Item_Metadata_Entity extends Entity {
|
||||||
|
|
||||||
// if its required, at least one must be filled
|
// if its required, at least one must be filled
|
||||||
$one_filled = false;
|
$one_filled = false;
|
||||||
$valid = true;
|
$valid = true;
|
||||||
foreach($value as $val) {
|
$dupe_array = array();
|
||||||
if (!empty($val))
|
foreach($value as $val) {
|
||||||
$one_filled = true;
|
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) {
|
if ($this->is_required() && !$one_filled) {
|
||||||
|
@ -505,7 +530,7 @@ class Item_Metadata_Entity extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_as_valid();
|
$this->set_as_valid();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// translators: %s = metadatum name. ex: Title is invalid
|
// translators: %s = metadatum name. ex: Title is invalid
|
||||||
$this->add_error( 'invalid', sprintf( __('%s is invalid', 'tainacan'), $metadatum->get_name() ) );
|
$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();
|
$this->set_as_valid();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue