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

This commit is contained in:
mateuswetah 2018-05-11 18:02:58 -03:00
commit 89d184f9dc
7 changed files with 278 additions and 213 deletions

View File

@ -493,7 +493,7 @@ class REST_Fields_Controller extends REST_Controller {
if($method === \WP_REST_Server::READABLE) {
$endpoint_args['fetch'] = [
'type' => 'string',
'description' => __('Fetch all values of a field from a collection in all it collection items'),
'description' => __('Fetch all values of a metadata within a collection'),
'enum' => ['all_field_values']
];
$endpoint_args['context'] = array(

View File

@ -41,8 +41,6 @@ class Capabilities {
"read"
],
"contributor"=> [
"delete_posts",
"edit_posts",
"read"
],
"subscriber"=> [

View File

@ -2,6 +2,8 @@
namespace Tainacan\Field_Types;
use Tainacan\Entities\Field;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
@ -59,5 +61,18 @@ class Core_Description extends Field_Type {
return $item->validate_prop('description');
}
public function validate_options( Field $field ) {
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
return true;
if ( $field->get_multiple() != 'no') {
return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')];
}
return true;
}
}

View File

@ -2,6 +2,9 @@
namespace Tainacan\Field_Types;
use Tainacan\Entities\Field;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
@ -59,5 +62,18 @@ class Core_Title extends Field_Type {
return $item->validate_prop('title');
}
public function validate_options( Field $field ) {
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
return true;
if ( $field->get_multiple() != 'no') {
return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')];
}
return true;
}
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -137,5 +137,38 @@ class CoreFieldTypes extends TAINACAN_UnitTestCase {
$this->assertTrue($i->validate(), 'Item with empy title should validate because core title field has value');
}
function test_dont_allow_multiple() {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test',
),
true
);
$fields = $Tainacan_Fields->fetch_by_collection( $collection, [], 'OBJECT' ) ;
foreach ( $fields as $index => $field ){
if ( $field->get_field_type_object()->get_core() && $field->get_field_type_object()->get_related_mapped_prop() == 'title') {
$core_title = $field;
}
if ( $field->get_field_type_object()->get_core() && $field->get_field_type_object()->get_related_mapped_prop() == 'description') {
$core_description = $field;
}
}
$core_title->set_multiple('yes');
$core_description->set_multiple('yes');
$this->assertFalse($core_title->validate(), 'Core metadata should not validate because it can not allow it to have multiple');
$this->assertFalse($core_description->validate(), 'Core metadata should not validate because it can not allow it to have multiple');
}
}