diff --git a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php index 206a8503b..869ddf47e 100644 --- a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -161,7 +161,13 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller { $field = $this->field_repository->fetch( $field_id ); $item_metadata = new Entities\Item_Metadata_Entity( $item, $field ); - $item_metadata->set_value( $value ); + if($item_metadata->is_multiple()) { + $item_metadata->set_value( $value ); + } elseif(is_array($value)) { + $item_metadata->set_value(implode(' ', $value)); + } else{ + $item_metadata->set_value($value); + } if ( $item_metadata->validate() ) { $field_updated = $this->item_metadata_repository->update( $item_metadata ); diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 760936768..ad2f0fb70 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -180,6 +180,11 @@ class Item_Metadata_Entity extends Entity { return false; } } else { + + if( is_array($value) ){ + $this->add_error('not_multiple', $field->get_name() . ' do not accept array as value'); + return false; + } if ($this->is_collection_key()) { $Tainacan_Items = new \Tainacan\Repositories\Items(); @@ -198,9 +203,7 @@ class Item_Metadata_Entity extends Entity { return false; } } - - // TODO: call fieldType validation - // + $this->set_as_valid(); return true; } diff --git a/src/classes/tainacan-creator.php b/src/classes/tainacan-creator.php index fa4ef6c44..24407120e 100644 --- a/src/classes/tainacan-creator.php +++ b/src/classes/tainacan-creator.php @@ -88,7 +88,6 @@ $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Numeric'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Selectbox'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Relationship'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Radio'); -$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Checkbox'); global $Tainacan_Filters; $Tainacan_Filters = new \Tainacan\Repositories\Filters();