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/'
|
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
|
while inotifywait -qqr src -e create,move,modify,delete; do
|
||||||
echo
|
echo
|
||||||
echo 'Change detected, running build'
|
echo 'Change detected, running build'
|
||||||
./build.sh
|
./build.sh
|
||||||
done
|
done
|
||||||
|
fi
|
|
@ -113,6 +113,8 @@ return [
|
||||||
'label_collection_items' => __('Collection Items', 'tainacan'),
|
'label_collection_items' => __('Collection Items', 'tainacan'),
|
||||||
'label_collection_fields' => __('Collection Fields', 'tainacan'),
|
'label_collection_fields' => __('Collection Fields', 'tainacan'),
|
||||||
'label_collection_filters' => __('Collection Filters', '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
|
// Instructions. More complex sentences to guide user and placeholders
|
||||||
'instruction_dragndrop_fields_collection' => __('Drag and drop Fields here to Collection.', 'tainacan'),
|
'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'),
|
'instruction_select_a_filter_type' => __('Select a filter type:', 'tainacan'),
|
||||||
|
|
||||||
// Info. Other feedback to user.
|
// 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_collection_created' => __('No collection was created in this repository.', 'tainacan'),
|
||||||
'info_no_item_created' => __('No item was created in this collection.', 'tainacan'),
|
'info_no_item_created' => __('No item was created in this collection.', 'tainacan'),
|
||||||
'info_error_deleting_collection' => __('Error on deleting 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>
|
<template>
|
||||||
|
<div>
|
||||||
<component
|
<component
|
||||||
:is="getComponent()"
|
:is="getComponent()"
|
||||||
v-model="valueComponent"
|
v-model="valueComponent"
|
||||||
:allowNew="allowNew"
|
:allowNew="allowNew"
|
||||||
:terms="terms"
|
:terms="terms"
|
||||||
:options="getOptions(0)"></component>
|
: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>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { tainacan as axios } from '../../../js/axios/axios'
|
import { tainacan as axios } from '../../../js/axios/axios'
|
||||||
import TainacanCategoryRadio from './CategoryRadio.vue'
|
import TainacanCategoryRadio from './CategoryRadio.vue'
|
||||||
import TainacanCategoryCheckbox from './CategoryCheckbox.vue'
|
import TainacanCategoryCheckbox from './CategoryCheckbox.vue'
|
||||||
import TainacanCategoryTagInput from './CategoryTaginput.vue'
|
import TainacanCategoryTagInput from './CategoryTaginput.vue'
|
||||||
|
import TainacanCategorySelectbox from './CategorySelectbox.vue'
|
||||||
|
import AddNewTerm from './AddNewTerm.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
created(){
|
created(){
|
||||||
|
@ -30,7 +43,9 @@
|
||||||
components: {
|
components: {
|
||||||
TainacanCategoryRadio,
|
TainacanCategoryRadio,
|
||||||
TainacanCategoryCheckbox,
|
TainacanCategoryCheckbox,
|
||||||
TainacanCategoryTagInput
|
TainacanCategoryTagInput,
|
||||||
|
TainacanCategorySelectbox,
|
||||||
|
AddNewTerm
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
|
@ -109,7 +124,21 @@
|
||||||
this.inputValue = $event;
|
this.inputValue = $event;
|
||||||
this.$emit('input', this.inputValue);
|
this.$emit('input', this.inputValue);
|
||||||
this.$emit('blur');
|
this.$emit('blur');
|
||||||
|
},
|
||||||
|
reload( val ){
|
||||||
|
this.valueComponent = val;
|
||||||
|
|
||||||
|
this.terms = [];
|
||||||
|
this.getTermsFromTaxonomy();
|
||||||
|
this.getTermsId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.add-new-term{
|
||||||
|
margin-top: 15px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="block" v-for="option,index in options">
|
<div v-for="option,index in options">
|
||||||
<b-checkbox
|
<b-checkbox
|
||||||
:id="id"
|
:id="id"
|
||||||
:style="{ paddingLeft: (option.level * 30) + 'px' }"
|
:style="{ paddingLeft: (option.level * 30) + 'px' }"
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
border>
|
border>
|
||||||
{{ option.name }}
|
{{ option.name }}
|
||||||
</b-checkbox>
|
</b-checkbox>
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -27,6 +28,11 @@
|
||||||
checked: []
|
checked: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
value( val ){
|
||||||
|
this.checked = val;
|
||||||
|
}
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
options: {
|
options: {
|
||||||
type: Array
|
type: Array
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="block" v-for="option,index in options">
|
<div v-for="option,index in options">
|
||||||
<b-radio
|
<b-radio
|
||||||
:id="id"
|
:id="id"
|
||||||
:style="{ paddingLeft: (option.level * 30) + 'px' }"
|
:style="{ paddingLeft: (option.level * 30) + 'px' }"
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
border>
|
border>
|
||||||
{{ option.name }}
|
{{ option.name }}
|
||||||
</b-radio>
|
</b-radio>
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -18,13 +19,14 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
created(){
|
|
||||||
if( this.value )
|
|
||||||
this.checked = this.value;
|
|
||||||
},
|
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
checked:''
|
checked: ( this.value ) ? this.value : ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
value( val ){
|
||||||
|
this.checked = val;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
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
|
rounded
|
||||||
icon="magnify"
|
icon="magnify"
|
||||||
:allowNew="allowNew"
|
:allowNew="allowNew"
|
||||||
|
@input="emitChange"
|
||||||
v-model="selected"
|
v-model="selected"
|
||||||
:data="labels"
|
:data="labels"
|
||||||
field="label"
|
field="label"
|
||||||
|
@ -22,19 +23,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
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 ){
|
terms( val ){
|
||||||
this.selectedValues();
|
this.selectedValues();
|
||||||
}
|
}
|
||||||
|
@ -74,6 +62,19 @@
|
||||||
}
|
}
|
||||||
this.selected = selected;
|
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
|
<?php
|
||||||
|
|
||||||
namespace Tainacan\Repositories;
|
namespace Tainacan\Repositories;
|
||||||
|
|
||||||
use Tainacan\Entities;
|
use Tainacan\Entities;
|
||||||
use Tainacan\Field_Types;
|
use Tainacan\Field_Types;
|
||||||
|
|
||||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||||
|
|
||||||
use \Respect\Validation\Validator as v;
|
use \Respect\Validation\Validator as v;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Fields
|
* Class Fields
|
||||||
*/
|
*/
|
||||||
|
@ -20,6 +22,7 @@ class Fields extends Repository {
|
||||||
'Tainacan\Field_Types\Core_Title',
|
'Tainacan\Field_Types\Core_Title',
|
||||||
'Tainacan\Field_Types\Core_Description'
|
'Tainacan\Field_Types\Core_Description'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register specific hooks for field repository
|
* Register specific hooks for field repository
|
||||||
*/
|
*/
|
||||||
|
@ -104,7 +107,8 @@ class Fields extends Repository {
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => __( 'Allow multiple fields for the field', 'tainacan' ),
|
'description' => __( 'Allow multiple fields for the field', 'tainacan' ),
|
||||||
'on_error' => __( 'Multiple fields is invalid', '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'
|
'default' => 'no'
|
||||||
],
|
],
|
||||||
'cardinality' => [
|
'cardinality' => [
|
||||||
|
@ -122,7 +126,8 @@ class Fields extends Repository {
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => __( 'The field should be omitted in item view', 'tainacan' ),
|
'description' => __( 'The field should be omitted in item view', 'tainacan' ),
|
||||||
'on_error' => __( 'Privacy is invalid', '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'
|
'default' => 'no'
|
||||||
],
|
],
|
||||||
'mask' => [
|
'mask' => [
|
||||||
|
@ -168,7 +173,8 @@ class Fields extends Repository {
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => __( 'The field can be deleted', 'tainacan' ),
|
'description' => __( 'The field can be deleted', 'tainacan' ),
|
||||||
'on_error' => __( 'Can delete is invalid', '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'
|
'default' => 'yes'
|
||||||
],
|
],
|
||||||
] );
|
] );
|
||||||
|
@ -176,6 +182,7 @@ class Fields extends Repository {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the labels for the custom post type of this repository
|
* Get the labels for the custom post type of this repository
|
||||||
|
*
|
||||||
* @return array Labels in the format expected by register_post_type()
|
* @return array Labels in the format expected by register_post_type()
|
||||||
*/
|
*/
|
||||||
public function get_cpt_labels() {
|
public function get_cpt_labels() {
|
||||||
|
@ -299,6 +306,7 @@ class Fields extends Repository {
|
||||||
$args['post_type'] = Entities\Field::get_post_type();
|
$args['post_type'] = Entities\Field::get_post_type();
|
||||||
|
|
||||||
$wp_query = new \WP_Query( $args );
|
$wp_query = new \WP_Query( $args );
|
||||||
|
|
||||||
return $this->fetch_output( $wp_query, $output );
|
return $this->fetch_output( $wp_query, $output );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -352,6 +360,7 @@ class Fields extends Repository {
|
||||||
* @param $result Response from method fetch
|
* @param $result Response from method fetch
|
||||||
* @param Entities\Collection $collection
|
* @param Entities\Collection $collection
|
||||||
* @param bool $include_disabled Wether to include disabled fields in the results or not
|
* @param bool $include_disabled Wether to include disabled fields in the results or not
|
||||||
|
*
|
||||||
* @return array or WP_Query ordinate
|
* @return array or WP_Query ordinate
|
||||||
*/
|
*/
|
||||||
public function order_result( $result, Entities\Collection $collection, $include_disabled = false ) {
|
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 );
|
$result_ordinate = array_merge( $result_ordinate, $not_ordinate );
|
||||||
|
|
||||||
return $result_ordinate;
|
return $result_ordinate;
|
||||||
}
|
} // if the result is a wp query object
|
||||||
// if the result is a wp query object
|
|
||||||
else {
|
else {
|
||||||
$posts = $result->posts;
|
$posts = $result->posts;
|
||||||
$result_ordinate = [];
|
$result_ordinate = [];
|
||||||
|
@ -412,11 +420,13 @@ class Fields extends Repository {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Tainacan\Entities\Field $field
|
* @param \Tainacan\Entities\Field $field
|
||||||
|
*
|
||||||
* @return \Tainacan\Entities\Field
|
* @return \Tainacan\Entities\Field
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @see \Tainacan\Repositories\Repository::insert()
|
* @see \Tainacan\Repositories\Repository::insert()
|
||||||
|
@ -428,6 +438,7 @@ class Fields extends Repository {
|
||||||
$new_field = parent::insert( $field );
|
$new_field = parent::insert( $field );
|
||||||
|
|
||||||
$this->update_category_field( $new_field );
|
$this->update_category_field( $new_field );
|
||||||
|
|
||||||
return $new_field;
|
return $new_field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,6 +455,7 @@ class Fields extends Repository {
|
||||||
|
|
||||||
public function delete( $field_id ) {
|
public function delete( $field_id ) {
|
||||||
$this->delete_category_field( $field_id );
|
$this->delete_category_field( $field_id );
|
||||||
|
|
||||||
return new Entities\Field( wp_trash_post( $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
|
* NAME - return an Array of the names of field types registered
|
||||||
*
|
*
|
||||||
* @param $output string CLASS | NAME
|
* @param $output string CLASS | NAME
|
||||||
|
*
|
||||||
* @return array of Entities\Field_Types\Field_Type classes path name
|
* @return array of Entities\Field_Types\Field_Type classes path name
|
||||||
*/
|
*/
|
||||||
public function fetch_field_types( $output = 'CLASS' ) {
|
public function fetch_field_types( $output = 'CLASS' ) {
|
||||||
|
@ -575,7 +588,7 @@ class Fields extends Repository {
|
||||||
array(
|
array(
|
||||||
'key' => 'collection_id',
|
'key' => 'collection_id',
|
||||||
'value' => $collection->get_id(),
|
'value' => $collection->get_id(),
|
||||||
'compare' => 'IN',
|
'compare' => '=',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'key' => 'field_type',
|
'key' => 'field_type',
|
||||||
|
@ -607,6 +620,7 @@ class Fields extends Repository {
|
||||||
|
|
||||||
if ( $field->validate() ) {
|
if ( $field->validate() ) {
|
||||||
$field = $this->insert( $field );
|
$field = $this->insert( $field );
|
||||||
|
|
||||||
return $field->get_id();
|
return $field->get_id();
|
||||||
} else {
|
} else {
|
||||||
throw new \ErrorException( 'The entity wasn\'t validated.' . print_r( $field->get_errors(), true ) );
|
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
|
* a field type category is inserted or removed
|
||||||
*
|
*
|
||||||
* @param [type] $field [description]
|
* @param [type] $field [description]
|
||||||
|
*
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
*/
|
*/
|
||||||
private function update_category_field( $field ) {
|
private function update_category_field( $field ) {
|
||||||
|
@ -749,8 +764,9 @@ class Fields extends Repository {
|
||||||
$field_type = $field->get_field_type_object();
|
$field_type = $field->get_field_type_object();
|
||||||
if ( $field_type->get_primitive_type() == 'term' ) {
|
if ( $field_type->get_primitive_type() == 'term' ) {
|
||||||
$removed_tax = $field_type->get_option( 'taxonomy_id' );
|
$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() );
|
do_action( 'tainacan-taxonomy-removed-from-collection', $removed_tax, $field->get_collection() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tainacan\Repositories;
|
namespace Tainacan\Repositories;
|
||||||
|
|
||||||
use Tainacan\Entities;
|
use Tainacan\Entities;
|
||||||
|
|
||||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
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 );
|
||||||
do_action( 'tainacan-insert-Item_Metadata_Entity', $item_metadata );
|
do_action( 'tainacan-insert-Item_Metadata_Entity', $item_metadata );
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ class Item_Metadata extends Repository {
|
||||||
*
|
*
|
||||||
* @return mixed|void
|
* @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 ) {
|
public function save_core_field_value( \Tainacan\Entities\Item_Metadata_Entity $item_metadata ) {
|
||||||
$field_type = $item_metadata->get_field()->get_field_type_object();
|
$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 );
|
$item->$set_method( is_array( $value ) ? $value[0] : $value );
|
||||||
if ( $item->validate_core_fields() ) {
|
if ( $item->validate_core_fields() ) {
|
||||||
global $Tainacan_Items;
|
global $Tainacan_Items;
|
||||||
$Tainacan_Items->insert($item);
|
$Tainacan_Items->update( $item );
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception( 'Item metadata should be validated beforehand' );
|
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.
|
* Get the value for a Item field.
|
||||||
*
|
*
|
||||||
* @param Entities\Item_Metadata_Entity $item_metadata
|
* @param Entities\Item_Metadata_Entity $item_metadata
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get_value( Entities\Item_Metadata_Entity $item_metadata ) {
|
public function get_value( Entities\Item_Metadata_Entity $item_metadata ) {
|
||||||
|
@ -125,6 +127,7 @@ class Item_Metadata extends Repository {
|
||||||
$item = $item_metadata->get_item();
|
$item = $item_metadata->get_item();
|
||||||
|
|
||||||
$get_method = 'get_' . $field_type->get_related_mapped_prop();
|
$get_method = 'get_' . $field_type->get_related_mapped_prop();
|
||||||
|
|
||||||
return $item->$get_method();
|
return $item->$get_method();
|
||||||
|
|
||||||
} elseif ( $field_type->get_primitive_type() == 'term' ) {
|
} 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 );
|
$terms = wp_get_object_terms( $item_metadata->get_item()->get_id(), $taxonomy_slug );
|
||||||
|
|
||||||
if ($unique)
|
if ( $unique ) {
|
||||||
$terms = reset( $terms );
|
$terms = reset( $terms );
|
||||||
|
}
|
||||||
|
|
||||||
return $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_map() {
|
||||||
public function get_default_properties($map) { return []; }
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_default_properties( $map ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $object
|
* @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
|
* Suggest a value to be inserted as a item Field value, return a pending log
|
||||||
|
*
|
||||||
* @param Entities\Item_Metadata_Entity $item_metadata
|
* @param Entities\Item_Metadata_Entity $item_metadata
|
||||||
|
*
|
||||||
* @return Entities\Log
|
* @return Entities\Log
|
||||||
*/
|
*/
|
||||||
public function suggest( $item_metadata ) {
|
public function suggest( $item_metadata ) {
|
||||||
|
|
|
@ -145,12 +145,12 @@ class Items extends Repository {
|
||||||
|
|
||||||
// iterate through the native post properties
|
// iterate through the native post properties
|
||||||
foreach ( $map as $prop => $mapped ) {
|
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 );
|
$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_type = $cpt;
|
||||||
//$item->WP_Post->post_status = 'publish';
|
//$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
|
* @package Test_Tainacan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Tainacan\Entities;
|
class CoreFieldTypes extends TAINACAN_UnitApiTestCase {
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample test case.
|
|
||||||
*/
|
|
||||||
class CoreFieldTypes extends TAINACAN_UnitTestCase {
|
|
||||||
|
|
||||||
|
|
||||||
function test_core_field_types() {
|
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