Merge branch 'develop' of https://github.com/tainacan/tainacan into develop
This commit is contained in:
commit
73319097f6
|
@ -4,8 +4,16 @@
|
|||
|
||||
echo 'Watching changes on src/'
|
||||
|
||||
current_OS=`uname`
|
||||
|
||||
# For macOS (Darwin) is needed fsevents-tools installed (you can use homebrew install fsevents-tools)
|
||||
if [ $current_OS == "Darwin" ]; then
|
||||
echo
|
||||
notifyloop src ./build.sh
|
||||
else
|
||||
while inotifywait -qqr src -e create,move,modify,delete; do
|
||||
echo
|
||||
echo 'Change detected, running build'
|
||||
./build.sh
|
||||
done
|
||||
fi
|
|
@ -113,6 +113,8 @@ return [
|
|||
'label_collection_items' => __('Collection Items', 'tainacan'),
|
||||
'label_collection_fields' => __('Collection Fields', 'tainacan'),
|
||||
'label_collection_filters' => __('Collection Filters', 'tainacan'),
|
||||
'label_parent_term' => __('Parent Term', 'tainacan'),
|
||||
'label_add_new_term' => __('Add New Term', 'tainacan'),
|
||||
|
||||
// Instructions. More complex sentences to guide user and placeholders
|
||||
'instruction_dragndrop_fields_collection' => __('Drag and drop Fields here to Collection.', 'tainacan'),
|
||||
|
@ -126,6 +128,7 @@ return [
|
|||
'instruction_select_a_filter_type' => __('Select a filter type:', 'tainacan'),
|
||||
|
||||
// Info. Other feedback to user.
|
||||
'info_name_is_required' => __('Name is required.', 'tainacan'),
|
||||
'info_no_collection_created' => __('No collection was created in this repository.', 'tainacan'),
|
||||
'info_no_item_created' => __('No item was created in this collection.', 'tainacan'),
|
||||
'info_error_deleting_collection' => __('Error on deleting collection.', 'tainacan'),
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
<template>
|
||||
<div>
|
||||
<span>
|
||||
<a
|
||||
class="button"
|
||||
@click="showForm = !showForm"><b-icon size="is-small" icon="plus"></b-icon> {{ $i18n.get('label_add_new_term') }}</a>
|
||||
</span>
|
||||
<div class="columns">
|
||||
<transition name="fade">
|
||||
|
||||
<section
|
||||
v-if="showForm"
|
||||
class="column is-one-third"
|
||||
style="padding-left: 0px;">
|
||||
|
||||
<b-field :label="$i18n.get('label_name')">
|
||||
<b-input v-model="name"></b-input>
|
||||
</b-field>
|
||||
|
||||
<b-field :label="$i18n.get('label_parent_term')">
|
||||
<b-select
|
||||
v-model="parent">
|
||||
<option :value="0" selected> ---{{ $i18n.get('label_parent_term') }}--- </option>
|
||||
<option
|
||||
v-for="option,index in options"
|
||||
:key="index"
|
||||
:value="option.term_id"
|
||||
v-html="setSpaces( option.level ) + option.name"></option>
|
||||
</b-select>
|
||||
</b-field>
|
||||
|
||||
<a
|
||||
class="button is-primary"
|
||||
@click="save">{{ $i18n.get('save') }}</a>
|
||||
</section>
|
||||
|
||||
</transition>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
<script>
|
||||
import { tainacan as axios } from '../../../js/axios/axios'
|
||||
|
||||
export default {
|
||||
data(){
|
||||
return {
|
||||
name: '',
|
||||
parent: 0,
|
||||
showForm: false,
|
||||
field_id: this.field.field.id
|
||||
}
|
||||
},
|
||||
props: {
|
||||
id: String,
|
||||
item_id: [Number,String],
|
||||
field: [Number,String],
|
||||
taxonomy_id: [Number,String],
|
||||
value:[ Array, Boolean, Number ],
|
||||
options: {
|
||||
type: Array
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setSpaces( level ){
|
||||
let result = '';
|
||||
let space = ' '
|
||||
|
||||
for(let i = 0;i < level; i++)
|
||||
result += space;
|
||||
|
||||
return result;
|
||||
},
|
||||
save(){
|
||||
if( this.name.trim() === ''){
|
||||
this.$toast.open({
|
||||
duration: 2000,
|
||||
message: this.$i18n.get('info_name_is_required'),
|
||||
position: 'is-bottom',
|
||||
type: 'is-danger'
|
||||
})
|
||||
} else {
|
||||
const instance = this;
|
||||
|
||||
axios.post(`/taxonomy/${this.taxonomy_id}/terms`, {
|
||||
name: this.name,
|
||||
parent: this.parent
|
||||
})
|
||||
.then( res => {
|
||||
instance.name = '';
|
||||
instance.parent = 0;
|
||||
|
||||
if( res.data && res.data.term_id || res.term_id ){
|
||||
let term_id = ( res.term_id ) ? res.term_id : res.data.term_id;
|
||||
let val = this.value;
|
||||
|
||||
if( !Array.isArray( val ) && this.field.field.multiple === 'no' ){
|
||||
axios.patch(`/item/${this.item_id}/metadata/${this.field_id}`, {
|
||||
values: term_id,
|
||||
}).then( res => {
|
||||
instance.$emit('newTerm', term_id);
|
||||
})
|
||||
} else {
|
||||
val = ( val ) ? val : [];
|
||||
val.push( term_id );
|
||||
axios.patch(`/item/${this.item_id}/metadata/${this.field_id}`, {
|
||||
values: val,
|
||||
}).then( res => {
|
||||
instance.$emit('newTerm', val);
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
button{
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
|
@ -1,16 +1,29 @@
|
|||
<template>
|
||||
<div>
|
||||
<component
|
||||
:is="getComponent()"
|
||||
v-model="valueComponent"
|
||||
:allowNew="allowNew"
|
||||
:terms="terms"
|
||||
:options="getOptions(0)"></component>
|
||||
<add-new-term
|
||||
class="add-new-term"
|
||||
v-if="getComponent() !== 'tainacan-category-tag-input' && allowNew"
|
||||
:taxonomy_id="taxonomy"
|
||||
:field="field"
|
||||
:item_id="field.item.id"
|
||||
:value="valueComponent"
|
||||
:options="getOptions(0)"
|
||||
@newTerm="reload"></add-new-term>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { tainacan as axios } from '../../../js/axios/axios'
|
||||
import TainacanCategoryRadio from './CategoryRadio.vue'
|
||||
import TainacanCategoryCheckbox from './CategoryCheckbox.vue'
|
||||
import TainacanCategoryTagInput from './CategoryTaginput.vue'
|
||||
import TainacanCategorySelectbox from './CategorySelectbox.vue'
|
||||
import AddNewTerm from './AddNewTerm.vue'
|
||||
|
||||
export default {
|
||||
created(){
|
||||
|
@ -30,7 +43,9 @@
|
|||
components: {
|
||||
TainacanCategoryRadio,
|
||||
TainacanCategoryCheckbox,
|
||||
TainacanCategoryTagInput
|
||||
TainacanCategoryTagInput,
|
||||
TainacanCategorySelectbox,
|
||||
AddNewTerm
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
|
@ -109,7 +124,21 @@
|
|||
this.inputValue = $event;
|
||||
this.$emit('input', this.inputValue);
|
||||
this.$emit('blur');
|
||||
},
|
||||
reload( val ){
|
||||
this.valueComponent = val;
|
||||
|
||||
this.terms = [];
|
||||
this.getTermsFromTaxonomy();
|
||||
this.getTermsId();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.add-new-term{
|
||||
margin-top: 15px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
</style>
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="block" v-for="option,index in options">
|
||||
<div v-for="option,index in options">
|
||||
<b-checkbox
|
||||
:id="id"
|
||||
:style="{ paddingLeft: (option.level * 30) + 'px' }"
|
||||
|
@ -11,6 +11,7 @@
|
|||
border>
|
||||
{{ option.name }}
|
||||
</b-checkbox>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -27,6 +28,11 @@
|
|||
checked: []
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value( val ){
|
||||
this.checked = val;
|
||||
}
|
||||
},
|
||||
props: {
|
||||
options: {
|
||||
type: Array
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="block" v-for="option,index in options">
|
||||
<div v-for="option,index in options">
|
||||
<b-radio
|
||||
:id="id"
|
||||
:style="{ paddingLeft: (option.level * 30) + 'px' }"
|
||||
|
@ -11,6 +11,7 @@
|
|||
border>
|
||||
{{ option.name }}
|
||||
</b-radio>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -18,13 +19,14 @@
|
|||
<script>
|
||||
|
||||
export default {
|
||||
created(){
|
||||
if( this.value )
|
||||
this.checked = this.value;
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
checked:''
|
||||
checked: ( this.value ) ? this.value : ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value( val ){
|
||||
this.checked = val;
|
||||
}
|
||||
},
|
||||
props: {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="block">
|
||||
<b-select
|
||||
:id="id"
|
||||
v-model="selected"
|
||||
@input="emitChange()"
|
||||
:placeholder="$i18n.get('label_select_category')" expanded>
|
||||
<option
|
||||
v-for="option,index in options"
|
||||
:key="index"
|
||||
:value="option.term_id"
|
||||
v-html="setSpaces( option.level ) + option.name"></option>
|
||||
</b-select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
created(){
|
||||
if( this.value )
|
||||
this.selected = this.value;
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
selected: ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value( val ){
|
||||
this.selected = val;
|
||||
}
|
||||
},
|
||||
props: {
|
||||
id: String,
|
||||
options: {
|
||||
type: Array
|
||||
},
|
||||
value: [ Number, String, Array ]
|
||||
},
|
||||
methods: {
|
||||
emitChange() {
|
||||
this.$emit('input', this.selected);
|
||||
this.$emit('blur');
|
||||
},
|
||||
setSpaces( level ){
|
||||
let result = '';
|
||||
let space = ' '
|
||||
|
||||
for(let i = 0;i < level; i++)
|
||||
result += space;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -5,6 +5,7 @@
|
|||
rounded
|
||||
icon="magnify"
|
||||
:allowNew="allowNew"
|
||||
@input="emitChange"
|
||||
v-model="selected"
|
||||
:data="labels"
|
||||
field="label"
|
||||
|
@ -22,19 +23,6 @@
|
|||
}
|
||||
},
|
||||
watch: {
|
||||
selected( val ){
|
||||
this.selected = val;
|
||||
let results = [];
|
||||
for( let term of val ){
|
||||
if( term.value ){
|
||||
results.push( term.value );
|
||||
} else {
|
||||
results.push( term );
|
||||
}
|
||||
}
|
||||
this.$emit('input', results);
|
||||
this.$emit('blur');
|
||||
},
|
||||
terms( val ){
|
||||
this.selectedValues();
|
||||
}
|
||||
|
@ -74,6 +62,19 @@
|
|||
}
|
||||
this.selected = selected;
|
||||
}
|
||||
},
|
||||
emitChange(){
|
||||
let val = this.selected;
|
||||
let results = [];
|
||||
for( let term of val ){
|
||||
if( term.value ){
|
||||
results.push( term.value );
|
||||
} else {
|
||||
results.push( term );
|
||||
}
|
||||
}
|
||||
this.$emit('input', results);
|
||||
this.$emit('blur');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Repositories;
|
||||
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Field_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
use \Respect\Validation\Validator as v;
|
||||
|
||||
/**
|
||||
* Class Fields
|
||||
*/
|
||||
|
@ -20,6 +22,7 @@ class Fields extends Repository {
|
|||
'Tainacan\Field_Types\Core_Title',
|
||||
'Tainacan\Field_Types\Core_Description'
|
||||
];
|
||||
|
||||
/**
|
||||
* Register specific hooks for field repository
|
||||
*/
|
||||
|
@ -104,7 +107,8 @@ class Fields extends Repository {
|
|||
'type' => 'string',
|
||||
'description' => __( 'Allow multiple fields for the field', 'tainacan' ),
|
||||
'on_error' => __( 'Multiple fields is invalid', 'tainacan' ),
|
||||
'validation' => v::stringType()->in(['yes', 'no']), // yes or no. It cant be multiple if its collection_key
|
||||
'validation' => v::stringType()->in( [ 'yes', 'no' ] ),
|
||||
// yes or no. It cant be multiple if its collection_key
|
||||
'default' => 'no'
|
||||
],
|
||||
'cardinality' => [
|
||||
|
@ -122,7 +126,8 @@ class Fields extends Repository {
|
|||
'type' => 'string',
|
||||
'description' => __( 'The field should be omitted in item view', 'tainacan' ),
|
||||
'on_error' => __( 'Privacy is invalid', 'tainacan' ),
|
||||
'validation' => v::stringType()->in(['yes', 'no']), // yes or no. It cant be multiple if its collection_key
|
||||
'validation' => v::stringType()->in( [ 'yes', 'no' ] ),
|
||||
// yes or no. It cant be multiple if its collection_key
|
||||
'default' => 'no'
|
||||
],
|
||||
'mask' => [
|
||||
|
@ -168,7 +173,8 @@ class Fields extends Repository {
|
|||
'type' => 'string',
|
||||
'description' => __( 'The field can be deleted', 'tainacan' ),
|
||||
'on_error' => __( 'Can delete is invalid', 'tainacan' ),
|
||||
'validation' => v::stringType()->in(['yes', 'no']), // yes or no. It cant be multiple if its collection_key
|
||||
'validation' => v::stringType()->in( [ 'yes', 'no' ] ),
|
||||
// yes or no. It cant be multiple if its collection_key
|
||||
'default' => 'yes'
|
||||
],
|
||||
] );
|
||||
|
@ -176,6 +182,7 @@ class Fields extends Repository {
|
|||
|
||||
/**
|
||||
* Get the labels for the custom post type of this repository
|
||||
*
|
||||
* @return array Labels in the format expected by register_post_type()
|
||||
*/
|
||||
public function get_cpt_labels() {
|
||||
|
@ -299,6 +306,7 @@ class Fields extends Repository {
|
|||
$args['post_type'] = Entities\Field::get_post_type();
|
||||
|
||||
$wp_query = new \WP_Query( $args );
|
||||
|
||||
return $this->fetch_output( $wp_query, $output );
|
||||
}
|
||||
}
|
||||
|
@ -352,6 +360,7 @@ class Fields extends Repository {
|
|||
* @param $result Response from method fetch
|
||||
* @param Entities\Collection $collection
|
||||
* @param bool $include_disabled Wether to include disabled fields in the results or not
|
||||
*
|
||||
* @return array or WP_Query ordinate
|
||||
*/
|
||||
public function order_result( $result, Entities\Collection $collection, $include_disabled = false ) {
|
||||
|
@ -387,8 +396,7 @@ class Fields extends Repository {
|
|||
$result_ordinate = array_merge( $result_ordinate, $not_ordinate );
|
||||
|
||||
return $result_ordinate;
|
||||
}
|
||||
// if the result is a wp query object
|
||||
} // if the result is a wp query object
|
||||
else {
|
||||
$posts = $result->posts;
|
||||
$result_ordinate = [];
|
||||
|
@ -412,11 +420,13 @@ class Fields extends Repository {
|
|||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Tainacan\Entities\Field $field
|
||||
*
|
||||
* @return \Tainacan\Entities\Field
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Repositories\Repository::insert()
|
||||
|
@ -428,6 +438,7 @@ class Fields extends Repository {
|
|||
$new_field = parent::insert( $field );
|
||||
|
||||
$this->update_category_field( $new_field );
|
||||
|
||||
return $new_field;
|
||||
}
|
||||
|
||||
|
@ -444,6 +455,7 @@ class Fields extends Repository {
|
|||
|
||||
public function delete( $field_id ) {
|
||||
$this->delete_category_field( $field_id );
|
||||
|
||||
return new Entities\Field( wp_trash_post( $field_id ) );
|
||||
}
|
||||
|
||||
|
@ -455,6 +467,7 @@ class Fields extends Repository {
|
|||
* NAME - return an Array of the names of field types registered
|
||||
*
|
||||
* @param $output string CLASS | NAME
|
||||
*
|
||||
* @return array of Entities\Field_Types\Field_Type classes path name
|
||||
*/
|
||||
public function fetch_field_types( $output = 'CLASS' ) {
|
||||
|
@ -575,7 +588,7 @@ class Fields extends Repository {
|
|||
array(
|
||||
'key' => 'collection_id',
|
||||
'value' => $collection->get_id(),
|
||||
'compare' => 'IN',
|
||||
'compare' => '=',
|
||||
),
|
||||
array(
|
||||
'key' => 'field_type',
|
||||
|
@ -607,6 +620,7 @@ class Fields extends Repository {
|
|||
|
||||
if ( $field->validate() ) {
|
||||
$field = $this->insert( $field );
|
||||
|
||||
return $field->get_id();
|
||||
} else {
|
||||
throw new \ErrorException( 'The entity wasn\'t validated.' . print_r( $field->get_errors(), true ) );
|
||||
|
@ -723,6 +737,7 @@ class Fields extends Repository {
|
|||
* a field type category is inserted or removed
|
||||
*
|
||||
* @param [type] $field [description]
|
||||
*
|
||||
* @return [type] [description]
|
||||
*/
|
||||
private function update_category_field( $field ) {
|
||||
|
@ -749,8 +764,9 @@ class Fields extends Repository {
|
|||
$field_type = $field->get_field_type_object();
|
||||
if ( $field_type->get_primitive_type() == 'term' ) {
|
||||
$removed_tax = $field_type->get_option( 'taxonomy_id' );
|
||||
if (!empty($removed_tax))
|
||||
if ( ! empty( $removed_tax ) ) {
|
||||
do_action( 'tainacan-taxonomy-removed-from-collection', $removed_tax, $field->get_collection() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Repositories;
|
||||
|
||||
use Tainacan\Entities;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
@ -34,7 +35,6 @@ class Item_Metadata extends Repository {
|
|||
}
|
||||
|
||||
|
||||
|
||||
do_action( 'tainacan-insert', $item_metadata );
|
||||
do_action( 'tainacan-insert-Item_Metadata_Entity', $item_metadata );
|
||||
|
||||
|
@ -46,7 +46,8 @@ class Item_Metadata extends Repository {
|
|||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function delete($item_metadata){}
|
||||
public function delete( $item_metadata ) {
|
||||
}
|
||||
|
||||
public function save_core_field_value( \Tainacan\Entities\Item_Metadata_Entity $item_metadata ) {
|
||||
$field_type = $item_metadata->get_field()->get_field_type_object();
|
||||
|
@ -57,7 +58,7 @@ class Item_Metadata extends Repository {
|
|||
$item->$set_method( is_array( $value ) ? $value[0] : $value );
|
||||
if ( $item->validate_core_fields() ) {
|
||||
global $Tainacan_Items;
|
||||
$Tainacan_Items->insert($item);
|
||||
$Tainacan_Items->update( $item );
|
||||
} else {
|
||||
throw new \Exception( 'Item metadata should be validated beforehand' );
|
||||
}
|
||||
|
@ -115,6 +116,7 @@ class Item_Metadata extends Repository {
|
|||
* Get the value for a Item field.
|
||||
*
|
||||
* @param Entities\Item_Metadata_Entity $item_metadata
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_value( Entities\Item_Metadata_Entity $item_metadata ) {
|
||||
|
@ -125,6 +127,7 @@ class Item_Metadata extends Repository {
|
|||
$item = $item_metadata->get_item();
|
||||
|
||||
$get_method = 'get_' . $field_type->get_related_mapped_prop();
|
||||
|
||||
return $item->$get_method();
|
||||
|
||||
} elseif ( $field_type->get_primitive_type() == 'term' ) {
|
||||
|
@ -142,8 +145,9 @@ class Item_Metadata extends Repository {
|
|||
|
||||
$terms = wp_get_object_terms( $item_metadata->get_item()->get_id(), $taxonomy_slug );
|
||||
|
||||
if ($unique)
|
||||
if ( $unique ) {
|
||||
$terms = reset( $terms );
|
||||
}
|
||||
|
||||
return $terms;
|
||||
|
||||
|
@ -153,10 +157,16 @@ class Item_Metadata extends Repository {
|
|||
|
||||
}
|
||||
|
||||
public function register_post_type() { }
|
||||
public function register_post_type() {
|
||||
}
|
||||
|
||||
public function get_map() { return []; }
|
||||
public function get_default_properties($map) { return []; }
|
||||
public function get_map() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function get_default_properties( $map ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
|
@ -169,7 +179,9 @@ class Item_Metadata extends Repository {
|
|||
|
||||
/**
|
||||
* Suggest a value to be inserted as a item Field value, return a pending log
|
||||
*
|
||||
* @param Entities\Item_Metadata_Entity $item_metadata
|
||||
*
|
||||
* @return Entities\Log
|
||||
*/
|
||||
public function suggest( $item_metadata ) {
|
||||
|
|
|
@ -145,12 +145,12 @@ class Items extends Repository {
|
|||
|
||||
// iterate through the native post properties
|
||||
foreach ( $map as $prop => $mapped ) {
|
||||
if ( $mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi' && $mapped['map'] != 'terms' && $mapped['map'] != 'thumbnail_id' ) {
|
||||
if ( $mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi' && $mapped['map'] != 'terms' ) {
|
||||
$item->WP_Post->{$mapped['map']} = $item->get_mapped_property( $prop );
|
||||
}
|
||||
}
|
||||
|
||||
// save post and geet its ID
|
||||
// save post and get its ID
|
||||
$item->WP_Post->post_type = $cpt;
|
||||
//$item->WP_Post->post_status = 'publish';
|
||||
|
||||
|
|
|
@ -107,14 +107,6 @@ class DevInterface {
|
|||
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
$col->get_db_identifier() . '_metadata_js',
|
||||
__('Field Components', 'tainacan'),
|
||||
array(&$this, 'metadata_components_metabox'),
|
||||
$col->get_db_identifier(), //post type
|
||||
'normal'
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,12 +8,7 @@ namespace Tainacan\Tests;
|
|||
* @package Test_Tainacan
|
||||
*/
|
||||
|
||||
use Tainacan\Entities;
|
||||
|
||||
/**
|
||||
* Sample test case.
|
||||
*/
|
||||
class CoreFieldTypes extends TAINACAN_UnitTestCase {
|
||||
class CoreFieldTypes extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
|
||||
function test_core_field_types() {
|
||||
|
@ -92,4 +87,53 @@ class CoreFieldTypes extends TAINACAN_UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
protected function get_fields( $collection ) {
|
||||
$request_fields = new \WP_REST_Request( 'GET', $this->namespace . '/collection/' . $collection->get_id() . '/fields' );
|
||||
|
||||
$response = $this->server->dispatch( $request_fields );
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function test_update_core_fields_status() {
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'test',
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
// GET
|
||||
$data1 = self::get_fields( $collection );
|
||||
|
||||
// PATCH
|
||||
$field_id = $data1[0]['id'];
|
||||
|
||||
$body = json_encode( array(
|
||||
'status' => 'private'
|
||||
) );
|
||||
|
||||
$request = new \WP_REST_Request( 'PATCH', $this->namespace . '/collection/' . $collection->get_id() . '/fields/' . $field_id );
|
||||
$request->set_body( $body );
|
||||
|
||||
$response = $this->server->dispatch( $request );
|
||||
|
||||
$data2 = $response->get_data();
|
||||
$this->assertEquals('private', $data2['status']);
|
||||
|
||||
// GET
|
||||
$data3 = self::get_fields( $collection );
|
||||
|
||||
$this->assertCount(2, $data3);
|
||||
|
||||
$statuses = [$data3[0]['status'], $data3[1]['status']];
|
||||
|
||||
$this->assertContains('private', $statuses);
|
||||
$this->assertContains('publish', $statuses);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue