Merge branch 'develop' of https://github.com/tainacan/tainacan into develop

This commit is contained in:
mateuswetah 2018-02-21 12:48:49 -03:00
commit fe215d7116
4 changed files with 25 additions and 3 deletions

View File

@ -210,6 +210,13 @@ class Item extends Entity {
$arrayItemMetadata = $this->get_fields(); $arrayItemMetadata = $this->get_fields();
if( $arrayItemMetadata ){ if( $arrayItemMetadata ){
foreach ( $arrayItemMetadata as $itemMetadata ) { foreach ( $arrayItemMetadata as $itemMetadata ) {
// avoid core fields to re-validate
$pos = strpos($itemMetadata->get_field()->get_field_type(), 'Core');
if( $pos !== false ){
continue;
}
if( !$itemMetadata->validate() ){ if( !$itemMetadata->validate() ){
$errors = $itemMetadata->get_errors(); $errors = $itemMetadata->get_errors();
$this->add_error( $itemMetadata->get_field()->get_name(), $errors ); $this->add_error( $itemMetadata->get_field()->get_name(), $errors );
@ -221,4 +228,15 @@ class Item extends Entity {
} }
return false; return false;
} }
/**
* {@inheritDoc}
* @see \Tainacan\Entities\Entity::validate()
*/
public function validate_core_fields(){
if ( !in_array($this->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
return true;
return parent::validate();
}
} }

View File

@ -289,8 +289,6 @@ class Fields extends Repository {
* @throws \Exception * @throws \Exception
*/ */
public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null){ public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null){
$this->register_core_fields( $collection );
$collection_id = $collection->get_id(); $collection_id = $collection->get_id();
//get parent collections //get parent collections

View File

@ -64,7 +64,7 @@ class Item_Metadata extends Repository {
$set_method = 'set_' . $field_type->related_mapped_prop; $set_method = 'set_' . $field_type->related_mapped_prop;
$value = $item_metadata->get_value(); $value = $item_metadata->get_value();
$item->$set_method( is_array( $value ) ? $value[0] : $value ); $item->$set_method( is_array( $value ) ? $value[0] : $value );
if ($item->validate()) { if ($item->validate_core_fields()) {
global $Tainacan_Items; global $Tainacan_Items;
$Tainacan_Items->insert($item); $Tainacan_Items->insert($item);
} else { } else {

View File

@ -475,6 +475,12 @@ class DevInterface {
foreach ($metalist as $meta) { foreach ($metalist as $meta) {
$item_meta = new \Tainacan\Entities\Item_Metadata_Entity($entity, $meta); $item_meta = new \Tainacan\Entities\Item_Metadata_Entity($entity, $meta);
$pos = strpos($item_meta->get_field()->get_field_type(), 'Core');
if( $pos !== false ){
continue;
}
if (isset($_POST['tnc_metadata_' . $meta->get_id()])) { if (isset($_POST['tnc_metadata_' . $meta->get_id()])) {
$item_meta->set_value($_POST['tnc_metadata_' . $meta->get_id()]); $item_meta->set_value($_POST['tnc_metadata_' . $meta->get_id()]);
if ($item_meta->validate()) { if ($item_meta->validate()) {