feat: add collection requirement and fix status #184

This commit is contained in:
vnmedeiros 2022-03-31 16:15:50 -03:00
parent 572176f03a
commit d6c38a33e7
4 changed files with 102 additions and 931 deletions

View File

@ -290,22 +290,6 @@ class REST_Metadata_Section_Controller extends REST_Controller {
$collection = new Entities\Collection( $collection_id );
$result = $this->metadatum_section_repository->fetch_by_collection( $collection, $args );
} else {
$args = [
'meta_query' => [
[
'key' => 'collection_id',
'value' => 'default',
'compare' => '='
]
]
];
if ($request['include_control_metadata_types'] === 'true') {
$args['include_control_metadata_types'] = true;
}
$result = $this->metadatum_section_repository->fetch( $args, 'OBJECT' );
}
$prepared_item = [];

View File

@ -124,6 +124,12 @@ class Metadatum_Section extends Entity {
$no_errors = true;
$metadatum_list = $this->get_metadatum_list();
$name = $this->get_name();
$collection = $this->get_collection();
if( empty($collection) ) {
$this->add_error($this->get_id(), __("collection is required", 'tainacan'));
$no_errors = false;
}
if ( !isset($name) ) {
$this->add_error($this->get_id(), __("name is required", 'tainacan'));
@ -137,6 +143,9 @@ class Metadatum_Section extends Entity {
}
}
}
if($no_errors) {
$this->set_as_valid();
}
return $no_errors;
}
}

View File

@ -52,7 +52,7 @@ class Metadata_Section extends Repository {
'map' => 'post_status',
'title' => __( 'Status', 'tainacan' ),
'type' => 'string',
'default' => 'public',
'default' => 'publish',
'description' => __( 'Status', 'tainacan' )
],
'description' => [
@ -233,8 +233,7 @@ class Metadata_Section extends Repository {
// Add public states.
$statuses = get_post_stati( array( 'public' => true ) );
$read_private_cap = $this->get_default_metadata_attribute() == $parent_id ? 'tnc_rep_read_private_metadata_section' : 'tnc_col_' . $parent_id . '_read_private_metadata_section';
$read_private_cap = 'tnc_col_' . $parent_id . '_read_private_metadata_section';
if ( current_user_can($read_private_cap) ) {
$statuses = array_merge( $statuses, get_post_stati( array( 'private' => true ) ) );
}

File diff suppressed because it is too large Load Diff