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

This commit is contained in:
mateuswetah 2020-05-05 10:49:10 -03:00
commit c3f3986b19
2 changed files with 16 additions and 12 deletions

View File

@ -366,22 +366,21 @@ class REST_Collections_Controller extends REST_Controller {
return new \WP_REST_Response($exception->getMessage(), 400);
}
if($prepared_post->validate()) {
$collection = $this->collections_repository->insert( $prepared_post );
$response = $this->prepare_item_for_response($collection, $request);
if($prepared_post->validate()) {
$collection = $this->collections_repository->insert( $prepared_post );
$response = $this->prepare_item_for_response($collection, $request);
do_action('tainacan-api-collection-created', $response, $request);
return new \WP_REST_Response($response, 201);
}
return new \WP_REST_Response($response, 201);
}
return new \WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $prepared_post->get_errors(),
'collection' => $this->prepare_item_for_response($prepared_post, $request)
], 400);
}
return new \WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $prepared_post->get_errors(),
'collection' => $this->prepare_item_for_response($prepared_post, $request)
], 400);
}
/**
* Verify if current has permission to create a item

View File

@ -746,6 +746,11 @@ class Collection extends Entity {
return true;
}
if( $this->is_cover_page_enabled() && !is_numeric( $this->get_cover_page_id() ) ) {
$this->add_error($this->get_id(), __('cover page is enabled, please inform the page', 'tainacan'));
return false;
}
return parent::validate();
}