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

This commit is contained in:
weryques 2018-09-04 15:22:40 -03:00
commit e5a0dd7ae1
27 changed files with 655 additions and 150 deletions

View File

@ -2,15 +2,16 @@
Notes for a future documentation Notes for a future documentation
Tainacan uses the ordinary WordPress template hierarchy for its templates. It adds only 3 additional templates in your hierarchy Tainacan uses the ordinary WordPress template hierarchy for its templates. It adds additional templates in the hierarchy
* `tainacan/single-items.php` - Used in the single template for any item of any collection * `tainacan/single-items.php` - Used in the single template for any item of any collection
* `tainacan/arhive-items.php` - Used in the list of items of any collection * `tainacan/arhive-items.php` - Used in the list of items of any collection (e.g. both archive-tnc_col_4_item.php and archive-tnc_col_5_item.php)
* `tainacan/archive-taxonomy.php` - Used as a template for all Tainacan Taxonomies (list items based on a term) * `tainacan/archive-taxonomy.php` - Used as a template for all Tainacan Taxonomies (list items based on a term)
* `tainacan/archive-repository.php` - Used in the `/items/` URL, which is added by the Tainacan plugin, and lists all items of all collections
Since each collection is a new custom post type, these templates are usefull to create a template that will be used by all collections. Since each collection is a new custom post type, these templates are usefull to create a template that will be used by all collections.
Nevertheless, you are still able to create more specific templates, using the standar WordPress hierarchy. Nevertheless, you are still able to create more specific templates, using the standard WordPress hierarchy.
Examples: Examples:

View File

@ -0,0 +1,9 @@
<?php
/**
* @see \Tainacan\Admin_Hooks->register()
*/
function register_admin_hook( $context, $callback, $position = 'end-left' ) {
$admin_hooks = \Tainacan\Admin_Hooks::get_instance();
return $admin_hooks->register( $context, $callback, $position );
}

View File

@ -0,0 +1,66 @@
<?php
namespace Tainacan;
class Admin_Hooks {
private $registered_hooks = [];
private static $instance = null;
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
add_action('init', [$this, 'init']);
}
function init() {
do_action('tainacan-register-admin-hooks');
}
public function get_available_positions() {
return apply_filters('tainacan-admin-hooks-positions', ['begin-left', 'begin-right', 'end-left', 'end-right']);
}
public function get_available_contexts() {
return apply_filters('tainacan-admin-hooks-contexts', ['collection', 'metadatum', 'item', 'taxonomy', 'term', 'filter']);
}
public function get_registered_hooks() {
return $this->registered_hooks;
}
/**
*
* @param string $context The context to add the hook to (collection, metadatum, item, taxonomy, term or filter)
* @param string $position The position inside the page to hook. (begin, end, begin-left, begin-right, end-left, end-right)
* @param callable $callback The callback that will output the form HTML
*/
public function register( $context, $callback, $position = 'end-left' ) {
$contexts = $this->get_available_contexts();
$positions = $this->get_available_positions();
if ( !in_array($context, $contexts) || !in_array($position, $positions) ) {
return false;
}
$result = call_user_func($callback);
if (is_string($result)){
$this->registered_hooks[$context][$position][] = $result;
return true;
}
return false;
}
}

View File

@ -205,6 +205,8 @@ class Admin {
$settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels(); $settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels();
} }
$settings['form_hooks'] = Admin_Hooks::get_instance()->get_registered_hooks();
return $settings; return $settings;
} }

View File

@ -27,6 +27,15 @@
@blur="updateSlug" @blur="updateSlug"
@focus="clearErrors('name')"/> @focus="clearErrors('name')"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['collection'] != undefined &&
formHooks['collection']['begin-left'] != undefined">
<form
id="form-collection-begin-left"
v-html="this.formHooks['collection']['begin-left'].join('')"/>
</template>
<!-- Thumbnail -------------------------------- --> <!-- Thumbnail -------------------------------- -->
<b-field :addons="false"> <b-field :addons="false">
@ -221,6 +230,18 @@
:title="$i18n.getHelperTitle('collections', 'allow_comments')" :title="$i18n.getHelperTitle('collections', 'allow_comments')"
:message="$i18n.getHelperMessage('collections', 'allow_comments')"/> :message="$i18n.getHelperMessage('collections', 'allow_comments')"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['collection'] != undefined &&
formHooks['collection']['end-left'] != undefined">
<form
ref="form-collection-end-left"
id="form-collection-end-left"
v-html="formHooks['collection']['end-left'].join('')"/>
</template>
</div> </div>
<div class="column is-1" /> <div class="column is-1" />
<div class="column"> <div class="column">
@ -285,6 +306,16 @@
</div> </div>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['collection'] != undefined &&
formHooks['collection']['begin-right'] != undefined">
<form
id="form-collection-begin-right"
v-html="formHooks['collection']['begin-right'].join('')"/>
</template>
<!-- Description -------------------------------- --> <!-- Description -------------------------------- -->
<b-field <b-field
:addons="false" :addons="false"
@ -385,7 +416,18 @@
v-model="form.slug" v-model="form.slug"
@focus="clearErrors('slug')"/> @focus="clearErrors('slug')"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['collection'] != undefined &&
formHooks['collection']['end-right'] != undefined">
<form
id="form-collection-end-right"
v-html="formHooks['collection']['end-right'].join('')"/>
</template>
</div> </div>
</div> </div>
<!-- Form submit -------------------------------- --> <!-- Form submit -------------------------------- -->
@ -418,11 +460,11 @@ import { mapActions } from 'vuex';
import wpMediaFrames from '../../js/wp-media-frames'; import wpMediaFrames from '../../js/wp-media-frames';
import FileItem from '../other/file-item.vue'; import FileItem from '../other/file-item.vue';
import EyeIcon from '../other/eye-icon.vue'; import EyeIcon from '../other/eye-icon.vue';
import { wpAjax } from '../../js/mixins'; import { wpAjax, formHooks } from '../../js/mixins';
export default { export default {
name: 'CollectionEditionForm', name: 'CollectionEditionForm',
mixins: [ wpAjax ], mixins: [ wpAjax, formHooks ],
data(){ data(){
return { return {
collectionId: Number, collectionId: Number,
@ -481,7 +523,7 @@ export default {
viewModesList: [], viewModesList: [],
fromImporter: '', fromImporter: '',
newPagePath: tainacan_plugin.admin_url + 'post-new.php?post_type=page', newPagePath: tainacan_plugin.admin_url + 'post-new.php?post_type=page',
isUpdatingSlug: false, isUpdatingSlug: false
} }
}, },
components: { components: {
@ -526,8 +568,8 @@ export default {
}); });
}, 500), }, 500),
onSubmit() { onSubmit() {
this.isLoading = true;
this.isLoading = true;
this.form.moderators_ids = []; this.form.moderators_ids = [];
for (let moderator of this.moderators) for (let moderator of this.moderators)
this.form.moderators_ids.push(moderator.id); this.form.moderators_ids.push(moderator.id);
@ -546,10 +588,16 @@ export default {
default_view_mode: this.form.default_view_mode, default_view_mode: this.form.default_view_mode,
allow_comments: this.form.allow_comments allow_comments: this.form.allow_comments
}; };
this.updateCollection(data).then(updatedCollection => { this.fillExtraFormData(data, 'collection');
this.updateCollection({collection_id: this.collectionId, collection: data })
.then(updatedCollection => {
this.collection = updatedCollection; this.collection = updatedCollection;
// Fills hook forms with it's real values
this.updateExtraFormData('collection', this.collection);
// Fill this.form data with current data. // Fill this.form data with current data.
this.form.name = this.collection.name; this.form.name = this.collection.name;
this.form.slug = this.collection.slug; this.form.slug = this.collection.slug;
@ -586,6 +634,8 @@ export default {
// Creates draft Collection // Creates draft Collection
let data = { name: '', description: '', status: 'auto-draft', mapper: (this.isMapped && this.mapper != false ? this.mapper : false ) }; let data = { name: '', description: '', status: 'auto-draft', mapper: (this.isMapped && this.mapper != false ? this.mapper : false ) };
this.fillExtraFormData(data, 'collection');
this.sendCollection(data).then(res => { this.sendCollection(data).then(res => {
this.collectionId = res.id; this.collectionId = res.id;
@ -758,7 +808,7 @@ export default {
} }
} }
}, },
created(){ mounted(){
if (this.$route.query.fromImporter != undefined) if (this.$route.query.fromImporter != undefined)
this.fromImporter = this.$route.query.fromImporter; this.fromImporter = this.$route.query.fromImporter;
@ -779,6 +829,12 @@ export default {
// Initializes Media Frames now that collectonId exists // Initializes Media Frames now that collectonId exists
this.initializeMediaFrames(); this.initializeMediaFrames();
this.$nextTick()
.then(() => {
// Fills hook forms with it's real values
this.updateExtraFormData('collection', this.collection);
});
// Fill this.form data with current data. // Fill this.form data with current data.
this.form.name = this.collection.name; this.form.name = this.collection.name;

View File

@ -3,6 +3,7 @@
id="filterEditForm" id="filterEditForm"
class="tainacan-form" class="tainacan-form"
@submit.prevent="saveEdition(editForm)"> @submit.prevent="saveEdition(editForm)">
<b-field <b-field
:addons="false" :addons="false"
:type="formErrors['name'] != undefined ? 'is-danger' : ''" :type="formErrors['name'] != undefined ? 'is-danger' : ''"
@ -22,6 +23,16 @@
@focus="clearErrors('name')"/> @focus="clearErrors('name')"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['filter'] != undefined &&
formHooks['filter']['begin-left'] != undefined">
<form
id="form-filter-begin-left"
v-html="formHooks['filter']['begin-left'].join('')"/>
</template>
<b-field <b-field
:addons="false" :addons="false"
:type="formErrors['description'] != undefined ? 'is-danger' : ''" :type="formErrors['description'] != undefined ? 'is-danger' : ''"
@ -136,6 +147,16 @@
v-html="editForm.edit_form" v-html="editForm.edit_form"
v-else/> v-else/>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['filter'] != undefined &&
formHooks['filter']['end-left'] != undefined">
<form
id="form-filter-end-left"
v-html="formHooks['filter']['end-left'].join('')"/>
</template>
<div class="field is-grouped form-submit"> <div class="field is-grouped form-submit">
<div class="control"> <div class="control">
<button <button
@ -156,9 +177,11 @@
<script> <script>
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import { formHooks } from "../../js/mixins";
export default { export default {
name: 'FilterEditionForm', name: 'FilterEditionForm',
mixins: [ formHooks ],
data(){ data(){
return { return {
editForm: {}, editForm: {},
@ -182,6 +205,13 @@ export default {
this.oldForm = JSON.parse(JSON.stringify(this.originalFilter)); this.oldForm = JSON.parse(JSON.stringify(this.originalFilter));
}, },
mounted() {
// Fills hook forms with it's real values
this.$nextTick()
.then(() => {
this.updateExtraFormData('filter', this.editForm);
});
},
beforeDestroy() { beforeDestroy() {
if (this.closedByForm) { if (this.closedByForm) {
this.editedFilter.saved = true; this.editedFilter.saved = true;
@ -201,6 +231,7 @@ export default {
if ((filter.filter_type_object && filter.filter_type_object.form_component) || filter.edit_form == '') { if ((filter.filter_type_object && filter.filter_type_object.form_component) || filter.edit_form == '') {
// this.fillExtraFormData(this.editForm, 'filter');
this.updateFilter({ filterId: filter.id, index: this.index, options: this.editForm}) this.updateFilter({ filterId: filter.id, index: this.index, options: this.editForm})
.then(() => { .then(() => {
this.editForm = {}; this.editForm = {};
@ -229,6 +260,7 @@ export default {
formObj[key] = value; formObj[key] = value;
} }
this.fillExtraFormData(formObj, 'filter');
this.updateFilter({ filterId: filter.id, index: this.index, options: formObj}) this.updateFilter({ filterId: filter.id, index: this.index, options: formObj})
.then(() => { .then(() => {
this.editForm = {}; this.editForm = {};
@ -265,7 +297,7 @@ export default {
@import "../../scss/_variables.scss"; @import "../../scss/_variables.scss";
form { form#filterEditForm {
padding: 1.0em 2.0em; padding: 1.0em 2.0em;
border-top: 1px solid $gray2; border-top: 1px solid $gray2;
border-bottom: 1px solid $gray2; border-bottom: 1px solid $gray2;

View File

@ -16,6 +16,16 @@
<div class="columns"> <div class="columns">
<div class="column is-5-5"> <div class="column is-5-5">
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['item'] != undefined &&
formHooks['item']['begin-left'] != undefined">
<form
id="form-item-begin-left"
v-html="formHooks['item']['begin-left'].join('')"/>
</template>
<!-- Document -------------------------------- --> <!-- Document -------------------------------- -->
<div class="section-label"> <div class="section-label">
<label>{{ form.document != undefined && form.document != null && form.document != '' ? $i18n.get('label_document') : $i18n.get('label_document_empty') }}</label> <label>{{ form.document != undefined && form.document != null && form.document != '' ? $i18n.get('label_document') : $i18n.get('label_document_empty') }}</label>
@ -292,11 +302,31 @@
</div> </div>
</div> </div>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['item'] != undefined &&
formHooks['item']['end-left'] != undefined">
<form
id="form-item-end-left"
v-html="formHooks['item']['end-left'].join('')"/>
</template>
</div> </div>
<div <div
class="column is-4-5" class="column is-4-5"
v-show="!isMetadataColumnCompressed"> v-show="!isMetadataColumnCompressed">
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['item'] != undefined &&
formHooks['item']['begin-right'] != undefined">
<form
id="form-item-begin-right"
v-html="formHooks['item']['begin-right'].join('')"/>
</template>
<!-- Visibility (status public or private) -------------------------------- --> <!-- Visibility (status public or private) -------------------------------- -->
<div class="section-label"> <div class="section-label">
@ -341,16 +371,14 @@
<!-- Metadata from Collection-------------------------------- --> <!-- Metadata from Collection-------------------------------- -->
<span class="section-label"> <span class="section-label">
<label >{{ $i18n.get('metadata') }}</label> <label>{{ $i18n.get('metadata') }}</label>
</span> </span>
<br> <br>
<a <a
class="collapse-all" class="collapse-all"
@click="toggleCollapseAll()"> @click="toggleCollapseAll()">
{{ collapseAll ? $i18n.get('label_collapse_all') : $i18n.get('label_expand_all') }} {{ collapseAll ? $i18n.get('label_collapse_all') : $i18n.get('label_expand_all') }}
<b-icon <b-icon :icon=" collapseAll ? 'menu-down' : 'menu-right'" />
type="is-turoquoise5"
:icon=" collapseAll ? 'menu-down' : 'menu-right'" />
</a> </a>
<tainacan-form-item <tainacan-form-item
v-for="(metadatum, index) of metadatumList" v-for="(metadatum, index) of metadatumList"
@ -359,6 +387,15 @@
:is-collapsed="metadatumCollapses[index]" :is-collapsed="metadatumCollapses[index]"
@changeCollapse="onChangeCollapse($event, index)"/> @changeCollapse="onChangeCollapse($event, index)"/>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['item'] != undefined &&
formHooks['item']['end-right'] != undefined">
<form
id="form-item-end-right"
v-html="formHooks['item']['end-right'].join('')"/>
</template>
</div> </div>
</div> </div>
<div class="footer"> <div class="footer">
@ -443,9 +480,11 @@ import wpMediaFrames from '../../js/wp-media-frames';
import FileItem from '../other/file-item.vue'; import FileItem from '../other/file-item.vue';
import DocumentItem from '../other/document-item.vue'; import DocumentItem from '../other/document-item.vue';
import CustomDialog from '../other/custom-dialog.vue'; import CustomDialog from '../other/custom-dialog.vue';
import { formHooks } from '../../js/mixins';
export default { export default {
name: 'ItemEditionForm', name: 'ItemEditionForm',
mixins: [ formHooks ],
data(){ data(){
return { return {
pageTitle: '', pageTitle: '',
@ -540,12 +579,15 @@ export default {
let previousStatus = this.form.status; let previousStatus = this.form.status;
this.form.status = status; this.form.status = status;
let data = {item_id: this.itemId, status: this.form.status, comment_status: this.form.comment_status}; let data = {id: this.itemId, status: this.form.status, comment_status: this.form.comment_status};
this.fillExtraFormData(data, 'item');
this.updateItem(data).then(updatedItem => { this.updateItem(data).then(updatedItem => {
this.item = updatedItem; this.item = updatedItem;
// Fills hook forms with it's real values
this.updateExtraFormData('item', this.item);
// Fill this.form data with current data. // Fill this.form data with current data.
this.form.status = this.item.status; this.form.status = this.item.status;
this.form.document = this.item.document; this.form.document = this.item.document;
@ -582,6 +624,7 @@ export default {
// Creates draft Item // Creates draft Item
let data = {collection_id: this.form.collectionId, status: 'auto-draft', comment_status: this.form.comment_status}; let data = {collection_id: this.form.collectionId, status: 'auto-draft', comment_status: this.form.comment_status};
this.fillExtraFormData(data, 'item');
this.sendItem(data).then(res => { this.sendItem(data).then(res => {
this.itemId = res.id; this.itemId = res.id;
@ -806,6 +849,12 @@ export default {
this.fetchItem(this.itemId).then(res => { this.fetchItem(this.itemId).then(res => {
this.item = res; this.item = res;
// Fills hook forms with it's real values
this.$nextTick()
.then(() => {
this.updateExtraFormData('item', this.item);
});
// Fill this.form data with current data. // Fill this.form data with current data.
this.form.status = this.item.status; this.form.status = this.item.status;
this.form.document = this.item.document; this.form.document = this.item.document;
@ -907,6 +956,10 @@ export default {
.page-container { .page-container {
padding: 25px 0px; padding: 25px 0px;
&>.tainacan-form {
margin-bottom: 110px;
}
.tainacan-page-title { .tainacan-page-title {
padding-left: $page-side-padding; padding-left: $page-side-padding;
padding-right: $page-side-padding; padding-right: $page-side-padding;
@ -945,7 +998,7 @@ export default {
label { label {
font-size: 16px !important; font-size: 16px !important;
font-weight: 500 !important; font-weight: 500 !important;
color: $blue5 !important; color: $gray5 !important;
line-height: 1.2em; line-height: 1.2em;
} }
} }

View File

@ -24,6 +24,16 @@
@focus="clearErrors('name')"/> @focus="clearErrors('name')"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['metadatum'] != undefined &&
formHooks['metadatum']['begin-left'] != undefined">
<form
id="form-metadatum-begin-left"
v-html="formHooks['metadatum']['begin-left'].join('')"/>
</template>
<b-field <b-field
:addons="false" :addons="false"
:type="formErrors['description'] != undefined ? 'is-danger' : ''" :type="formErrors['description'] != undefined ? 'is-danger' : ''"
@ -206,6 +216,16 @@
v-html="editForm.edit_form" v-html="editForm.edit_form"
v-else/> v-else/>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['metadatum'] != undefined &&
formHooks['metadatum']['end-left'] != undefined">
<form
id="form-metadatum-end-left"
v-html="formHooks['metadatum']['end-left'].join('')"/>
</template>
<div class="field is-grouped form-submit"> <div class="field is-grouped form-submit">
<div class="control"> <div class="control">
<button <button
@ -228,9 +248,11 @@
<script> <script>
import {mapActions} from 'vuex'; import {mapActions} from 'vuex';
import { formHooks } from "../../js/mixins";
export default { export default {
name: 'MetadatumEditionForm', name: 'MetadatumEditionForm',
mixins: [ formHooks ],
data() { data() {
return { return {
editForm: {}, editForm: {},
@ -257,6 +279,13 @@
this.oldForm = JSON.parse(JSON.stringify(this.originalMetadatum)); this.oldForm = JSON.parse(JSON.stringify(this.originalMetadatum));
}, },
mounted() {
// Fills hook forms with it's real values
this.$nextTick()
.then(() => {
this.updateExtraFormData('metadatum', this.editForm);
});
},
beforeDestroy() { beforeDestroy() {
if (this.closedByForm) { if (this.closedByForm) {
this.editedMetadatum.saved = true; this.editedMetadatum.saved = true;
@ -276,6 +305,7 @@
if ((metadatum.metadata_type_object && metadatum.metadata_type_object.form_component) || metadatum.edit_form == '') { if ((metadatum.metadata_type_object && metadatum.metadata_type_object.form_component) || metadatum.edit_form == '') {
this.fillExtraFormData(this.editForm, 'metadatum');
this.updateMetadatum({ this.updateMetadatum({
collectionId: this.collectionId, collectionId: this.collectionId,
metadatumId: metadatum.id, metadatumId: metadatum.id,
@ -309,6 +339,7 @@
for (let [key, value] of formData.entries()) for (let [key, value] of formData.entries())
formObj[key] = value; formObj[key] = value;
this.fillExtraFormData(formObj, 'metadatum');
this.updateMetadatum({ this.updateMetadatum({
collectionId: this.collectionId, collectionId: this.collectionId,
metadatumId: metadatum.id, metadatumId: metadatum.id,

View File

@ -25,6 +25,16 @@
@blur="updateSlug()"/> @blur="updateSlug()"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['taxonomy'] != undefined &&
formHooks['taxonomy']['begin-left'] != undefined">
<form
id="form-taxonomy-begin-left"
v-html="formHooks['taxonomy']['begin-left'].join('')"/>
</template>
<!-- Description -------------------------------- --> <!-- Description -------------------------------- -->
<b-field <b-field
:addons="false" :addons="false"
@ -99,6 +109,16 @@
</div> </div>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['taxonomy'] != undefined &&
formHooks['taxonomy']['end-left'] != undefined">
<form
id="form-taxonomy-end-left"
v-html="formHooks['taxonomy']['end-left'].join('')"/>
</template>
<!-- Submit --> <!-- Submit -->
<div class="field is-grouped form-submit"> <div class="field is-grouped form-submit">
<div class="control"> <div class="control">
@ -133,14 +153,14 @@
</template> </template>
<script> <script>
import { wpAjax } from "../../js/mixins"; import { wpAjax, formHooks } from "../../js/mixins";
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import TermsList from '../lists/terms-list.vue'; import TermsList from '../lists/terms-list.vue';
import CustomDialog from '../other/custom-dialog.vue'; import CustomDialog from '../other/custom-dialog.vue';
export default { export default {
name: 'TaxonomyEditionForm', name: 'TaxonomyEditionForm',
mixins: [ wpAjax ], mixins: [ wpAjax, formHooks ],
data(){ data(){
return { return {
taxonomyId: String, taxonomyId: String,
@ -169,8 +189,7 @@
label: this.$i18n.get('trash') label: this.$i18n.get('trash')
}], }],
editFormErrors: {}, editFormErrors: {},
formErrorMessage: '', formErrorMessage: ''
// baseUrl: tainacan_plugin.base_url,
} }
}, },
components: { components: {
@ -225,16 +244,19 @@
taxonomyId: this.taxonomyId, taxonomyId: this.taxonomyId,
name: this.form.name, name: this.form.name,
description: this.form.description, description: this.form.description,
slug: this.form.slug, slug: this.form.slug ? this.form.slug : '',
status: this.form.status, status: this.form.status,
allowInsert: this.form.allowInsert allow_insert: this.form.allowInsert
}; };
this.fillExtraFormData(data, 'taxonomy');
this.updateTaxonomy(data) this.updateTaxonomy(data)
.then(updatedTaxonomy => { .then(updatedTaxonomy => {
this.taxonomy = updatedTaxonomy; this.taxonomy = updatedTaxonomy;
// Fills hook forms with it's real values
this.updateExtraFormData('taxonomy', this.taxonomy);
// Fill this.form data with current data. // Fill this.form data with current data.
this.form.name = this.taxonomy.name; this.form.name = this.taxonomy.name;
this.form.slug = this.taxonomy.slug; this.form.slug = this.taxonomy.slug;
@ -291,9 +313,9 @@
description: '', description: '',
status: 'auto-draft', status: 'auto-draft',
slug: '', slug: '',
allowInsert: '', allow_insert: '',
}; };
this.fillExtraFormData(data, 'taxonomy');
this.createTaxonomy(data) this.createTaxonomy(data)
.then(res => { .then(res => {
@ -324,7 +346,7 @@
return ( this.form.allowInsert === 'yes' ) ? this.$i18n.get('label_yes') : this.$i18n.get('label_no'); return ( this.form.allowInsert === 'yes' ) ? this.$i18n.get('label_yes') : this.$i18n.get('label_no');
} }
}, },
created(){ mounted(){
if (this.$route.fullPath.split("/").pop() === "new") { if (this.$route.fullPath.split("/").pop() === "new") {
this.createNewTaxonomy(); this.createNewTaxonomy();
@ -339,6 +361,12 @@
this.fetchTaxonomy(this.taxonomyId).then(res => { this.fetchTaxonomy(this.taxonomyId).then(res => {
this.taxonomy = res.taxonomy; this.taxonomy = res.taxonomy;
// Fills hook forms with it's real values
this.$nextTick()
.then(() => {
this.updateExtraFormData('taxonomy', this.taxonomy);
});
// Fill this.form data with current data. // Fill this.form data with current data.
this.form.name = this.taxonomy.name; this.form.name = this.taxonomy.name;
this.form.description = this.taxonomy.description; this.form.description = this.taxonomy.description;

View File

@ -63,6 +63,16 @@
@focus="clearErrors({ name: 'name', repeated: 'repeated' })"/> @focus="clearErrors({ name: 'name', repeated: 'repeated' })"/>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['term'] != undefined &&
formHooks['term']['begin-left'] != undefined">
<form
id="form-term-begin-left"
v-html="formHooks['term']['begin-left'].join('')"/>
</template>
<!-- Description -------------- --> <!-- Description -------------- -->
<b-field <b-field
:addons="false" :addons="false"
@ -122,6 +132,16 @@
</transition> </transition>
</b-field> </b-field>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['term'] != undefined &&
formHooks['term']['end-left'] != undefined">
<form
id="form-term-end-left"
v-html="formHooks['term']['end-left'].join('')"/>
</template>
<!-- Submit buttons -------------- --> <!-- Submit buttons -------------- -->
<div class="field is-grouped form-submit"> <div class="field is-grouped form-submit">
<div class="control"> <div class="control">
@ -154,11 +174,13 @@
</template> </template>
<script> <script>
import { formHooks } from "../../js/mixins";
import {mapActions, mapGetters} from 'vuex'; import {mapActions, mapGetters} from 'vuex';
import wpMediaFrames from '../../js/wp-media-frames'; import wpMediaFrames from '../../js/wp-media-frames';
export default { export default {
name: 'TermEditionForm', name: 'TermEditionForm',
mixins: [ formHooks ],
data() { data() {
return { return {
formErrors: {}, formErrors: {},
@ -190,12 +212,16 @@
saveEdition(term) { saveEdition(term) {
if (term.id === 'new') { if (term.id === 'new') {
this.sendChildTerm({ let data = {
taxonomyId: this.taxonomyId,
name: this.editForm.name, name: this.editForm.name,
description: this.editForm.description, description: this.editForm.description,
parent: this.hasParent ? this.editForm.parent : 0, parent: this.hasParent ? this.editForm.parent : 0,
headerImageId: this.editForm.header_image_id, header_image_id: this.editForm.header_image_id,
};
this.fillExtraFormData(data, 'term');
this.sendChildTerm({
taxonomyId: this.taxonomyId,
term: data
}) })
.then((term) => { .then((term) => {
this.$emit('onEditionFinished', {term: term, hasChangedParent: this.hasChangedParent }); this.$emit('onEditionFinished', {term: term, hasChangedParent: this.hasChangedParent });
@ -213,13 +239,17 @@
} else { } else {
this.updateChildTerm({ let data = {
taxonomyId: this.taxonomyId, term_id: this.editForm.id,
termId: this.editForm.id,
name: this.editForm.name, name: this.editForm.name,
description: this.editForm.description, description: this.editForm.description,
parent: this.hasParent ? this.editForm.parent : 0, parent: this.hasParent ? this.editForm.parent : 0,
headerImageId: this.editForm.header_image_id, header_image_id: this.editForm.header_image_id,
}
this.fillExtraFormData(data, 'term');
this.updateChildTerm({
taxonomyId: this.taxonomyId,
term: data
}) })
.then((term) => { .then((term) => {
this.formErrors = {}; this.formErrors = {};
@ -312,6 +342,12 @@
}, },
mounted() { mounted() {
// Fills hook forms with it's real values
this.$nextTick()
.then(() => {
this.updateExtraFormData('term', this.editForm);
});
this.showCheckboxesWarning = false; this.showCheckboxesWarning = false;
this.hasParent = this.editForm.parent != undefined && this.editForm.parent > 0; this.hasParent = this.editForm.parent != undefined && this.editForm.parent > 0;
this.initialParentId = this.editForm.parent; this.initialParentId = this.editForm.parent;
@ -358,7 +394,7 @@
} }
} }
form { form#termEditForm {
padding: 1.7rem 0 1.5rem 1.5rem; padding: 1.7rem 0 1.5rem 1.5rem;
border-left: 1px solid $gray2; border-left: 1px solid $gray2;
margin-left: 0.75rem; margin-left: 0.75rem;

View File

@ -583,12 +583,6 @@ export default {
} }
} }
form {
padding: 1.0em 2.0em;
border-top: 1px solid $gray2;
border-bottom: 1px solid $gray2;
margin-top: 1.0em;
}
&.not-sortable-item, &.not-sortable-item:hover { &.not-sortable-item, &.not-sortable-item:hover {
cursor: default; cursor: default;
background-color: white !important; background-color: white !important;

View File

@ -47,3 +47,79 @@ export const dateInter = {
} }
} }
}; };
// Used for filling extra form data on hooks
export const formHooks = {
data() {
return {
formHooks: JSON.parse(JSON.stringify(tainacan_plugin['form_hooks']))
}
},
methods: {
fillExtraFormData(data, entity) {
let positions = [
'begin-left',
'begin-right',
'end-left',
'end-right'
];
// Gets data from existing extra form hooks
for (let position of positions) {
if (this.formHooks[entity][position] && this.formHooks[entity][position] != undefined) {
let formElement = document.getElementById('form-' + entity + '-' + position);
if (formElement) {
for (let element of formElement.elements) {
if (element.type == "checkbox" || (element.type == "select" && element.multiple != undefined && element.multiple == true)) {
if (element.checked && element.name != undefined && element.name != '') {
if (!Array.isArray(data[element.name]))
data[element.name] = [];
data[element.name].push(element.value);
}
} else if (element.type == "radio") {
if (element.checked && element.name != undefined && element.name != '')
data[element.name] = element.value;
} else {
data[element.name] = element.value;
}
}
}
}
}
},
updateExtraFormData(entity, entityObject) {
let positions = [
'begin-left',
'begin-right',
'end-left',
'end-right'
];
// Gets data from existing extra form hooks
for (let position of positions) {
if (this.formHooks[entity][position] && this.formHooks[entity][position] != undefined) {
let formElement = document.getElementById('form-' + entity + '-' + position);
if (formElement) {
for (let element of formElement.elements) {
for (let key of Object.keys(entityObject)) {
if (element['name'] == key) {
if (Array.isArray(entityObject[key])) {
let obj = entityObject[key].find((value) => { return value == element['value'] });
element['checked'] = obj != undefined ? true : false;
} else {
if (entityObject[key] != null && entityObject[key] != undefined && entityObject[key] != ''){
if (element.type == "radio")
element['checked'] = entityObject[key] == element['value'] ? true : false;
else
element['value'] = entityObject[key];
}
}
}
}
}
}
}
}
}
}
};

View File

@ -13,6 +13,16 @@
<div class="columns"> <div class="columns">
<div class="column is-5-5"> <div class="column is-5-5">
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['view-item'] != undefined &&
formHooks['view-item']['begin-left'] != undefined">
<div
id="view-item-begin-left"
v-html="formHooks['view-item']['begin-left'].join('')"/>
</template>
<!-- Document -------------------------------- --> <!-- Document -------------------------------- -->
<div class="section-label"> <div class="section-label">
<label>{{ item.document !== undefined && item.document !== null && item.document !== '' ? <label>{{ item.document !== undefined && item.document !== null && item.document !== '' ?
@ -156,11 +166,32 @@
</b-collapse> </b-collapse>
</div> </div>
</div> </div>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['view-item'] != undefined &&
formHooks['view-item']['end-left'] != undefined">
<div
id="view-item-end-left"
v-html="formHooks['view-item']['end-left'].join('')"/>
</template>
</div> </div>
<div <div
v-show="!isMetadataColumnCompressed" v-show="!isMetadataColumnCompressed"
class="column is-4-5"> class="column is-4-5">
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['view-item'] != undefined &&
formHooks['view-item']['begin-right'] != undefined">
<div
id="view-item-begin-right"
v-html="formHooks['view-item']['begin-right'].join('')"/>
</template>
<!-- Visibility (status public or private) -------------------------------- --> <!-- Visibility (status public or private) -------------------------------- -->
<div class="section-label"> <div class="section-label">
<label>{{ $i18n.get('label_visibility') }}</label> <label>{{ $i18n.get('label_visibility') }}</label>
@ -235,6 +266,16 @@
</b-collapse> </b-collapse>
</div> </div>
</div> </div>
<!-- Hook for extra Form options -->
<template
v-if="formHooks != undefined &&
formHooks['view-item'] != undefined &&
formHooks['view-item']['end-right'] != undefined">
<div
id="view-item-end-right"
v-html="formHooks['view-item']['end-right'].join('')"/>
</template>
</div> </div>
</div> </div>
<div class="footer"> <div class="footer">
@ -260,9 +301,11 @@
import {mapActions, mapGetters} from 'vuex' import {mapActions, mapGetters} from 'vuex'
import FileItem from '../../components/other/file-item.vue'; import FileItem from '../../components/other/file-item.vue';
import DocumentItem from '../../components/other/document-item.vue'; import DocumentItem from '../../components/other/document-item.vue';
import { formHooks } from '../../js/mixins';
export default { export default {
name: 'ItemPage', name: 'ItemPage',
mixins: [ formHooks ],
data() { data() {
return { return {
collectionId: Number, collectionId: Number,
@ -329,6 +372,9 @@
}, },
computed: { computed: {
item() { item() {
// Fills hook forms with it's real values
this.updateExtraFormData('item', this.getItem());
return this.getItem(); return this.getItem();
}, },
metadatumList() { metadatumList() {
@ -411,6 +457,10 @@
.page-container { .page-container {
padding: 25px 0; padding: 25px 0;
&>.tainacan-form {
margin-bottom: 110px;
}
.tainacan-page-title { .tainacan-page-title {
padding-left: $page-side-padding; padding-left: $page-side-padding;
padding-right: $page-side-padding; padding-right: $page-side-padding;
@ -472,7 +522,7 @@
label { label {
font-size: 16px !important; font-size: 16px !important;
font-weight: 500 !important; font-weight: 500 !important;
color: $blue5 !important; color: $gray5 !important;
line-height: 1.2em; line-height: 1.2em;
} }
} }

View File

@ -203,6 +203,19 @@ class REST_Collections_Controller extends REST_Controller {
$item_arr['total_items']['private'] = $total_items->private; $item_arr['total_items']['private'] = $total_items->private;
} }
/**
* Use this filter to add additional post_meta to the api response
* Use the $request object to get the context of the request and other variables
* For example, id context is edit, you may want to add your meta or not.
*
* Also take care to do any permissions verification before exposing the data
*/
$extra_metadata = apply_filters('tainacan-api-response-collection-meta', [], $request);
foreach ($extra_metadata as $extra_meta) {
$item_arr[$extra_meta] = get_post_meta($item_arr['id'], $extra_meta, true);
}
return $item_arr; return $item_arr;
} }

View File

@ -331,6 +331,19 @@ class REST_Filters_Controller extends REST_Controller {
$item_arr['filter_type_object'] = $item->get_filter_type_object() ? $item->get_filter_type_object()->_toArray() : $item->get_filter_type_object(); $item_arr['filter_type_object'] = $item->get_filter_type_object() ? $item->get_filter_type_object()->_toArray() : $item->get_filter_type_object();
/**
* Use this filter to add additional post_meta to the api response
* Use the $request object to get the context of the request and other variables
* For example, id context is edit, you may want to add your meta or not.
*
* Also take care to do any permissions verification before exposing the data
*/
$extra_metadata = apply_filters('tainacan-api-response-filter-meta', [], $request);
foreach ($extra_metadata as $extra_meta) {
$item_arr[$extra_meta] = get_post_meta($item_arr['id'], $extra_meta, true);
}
return $item_arr; return $item_arr;
} }

View File

@ -183,6 +183,19 @@ class REST_Items_Controller extends REST_Controller {
$item_arr['url'] = get_permalink( $item_arr['id'] ); $item_arr['url'] = get_permalink( $item_arr['id'] );
$item_arr['exposer_urls'] = \Tainacan\Exposers\Exposers::get_exposer_urls(get_rest_url(null, "{$this->namespace}/{$this->rest_base}/{$item->get_id()}/")); $item_arr['exposer_urls'] = \Tainacan\Exposers\Exposers::get_exposer_urls(get_rest_url(null, "{$this->namespace}/{$this->rest_base}/{$item->get_id()}/"));
/**
* Use this filter to add additional post_meta to the api response
* Use the $request object to get the context of the request and other variables
* For example, id context is edit, you may want to add your meta or not.
*
* Also take care to do any permissions verification before exposing the data
*/
$extra_metadata = apply_filters('tainacan-api-response-item-meta', [], $request);
foreach ($extra_metadata as $extra_meta) {
$item_arr[$extra_meta] = get_post_meta($item_arr['id'], $extra_meta, true);
}
return $item_arr; return $item_arr;
} }

View File

@ -321,6 +321,19 @@ class REST_Metadata_Controller extends REST_Controller {
$item_arr['enabled'] = $item->get_enabled_for_collection(); $item_arr['enabled'] = $item->get_enabled_for_collection();
} }
/**
* Use this filter to add additional post_meta to the api response
* Use the $request object to get the context of the request and other variables
* For example, id context is edit, you may want to add your meta or not.
*
* Also take care to do any permissions verification before exposing the data
*/
$extra_metadata = apply_filters('tainacan-api-response-metadatum-meta', [], $request);
foreach ($extra_metadata as $extra_meta) {
$item_arr[$extra_meta] = get_post_meta($item_arr['id'], $extra_meta, true);
}
return $item_arr; return $item_arr;
} }

View File

@ -106,6 +106,19 @@ class REST_Taxonomies_Controller extends REST_Controller {
$item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter); $item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter);
} }
/**
* Use this filter to add additional post_meta to the api response
* Use the $request object to get the context of the request and other variables
* For example, id context is edit, you may want to add your meta or not.
*
* Also take care to do any permissions verification before exposing the data
*/
$extra_metadata = apply_filters('tainacan-api-response-taxonomy-meta', [], $request);
foreach ($extra_metadata as $extra_meta) {
$item_arr[$extra_meta] = get_post_meta($item_arr['id'], $extra_meta, true);
}
return $item_arr; return $item_arr;
} }

View File

@ -277,6 +277,19 @@ class REST_Terms_Controller extends REST_Controller {
$item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter); $item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter);
} }
/**
* Use this filter to add additional term_meta to the api response
* Use the $request object to get the context of the request and other variables
* For example, id context is edit, you may want to add your meta or not.
*
* Also take care to do any permissions verification before exposing the data
*/
$extra_metadata = apply_filters('tainacan-api-response-term-meta', [], $request);
foreach ($extra_metadata as $extra_meta) {
$item_arr[$extra_meta] = get_term_meta($item_arr['id'], $extra_meta, true);
}
return $item_arr; return $item_arr;
} }

View File

@ -131,6 +131,10 @@ $Tainacan_Embed = \Tainacan\Embed::get_instance();
require_once(__DIR__ . '/../admin/class-tainacan-admin.php'); require_once(__DIR__ . '/../admin/class-tainacan-admin.php');
$Tainacan_Admin = \Tainacan\Admin::get_instance(); $Tainacan_Admin = \Tainacan\Admin::get_instance();
require_once(__DIR__ . '/../admin/class-tainacan-admin-hooks.php');
require_once(__DIR__ . '/../admin/admin-hooks-functions.php');
$Tainacan_Admin_Hooks = \Tainacan\Admin_Hooks::get_instance();
require_once(__DIR__ . '/../theme-helper/class-tainacan-theme-helper.php'); require_once(__DIR__ . '/../theme-helper/class-tainacan-theme-helper.php');
require_once(__DIR__ . '/../theme-helper/template-tags.php'); require_once(__DIR__ . '/../theme-helper/template-tags.php');
$Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance(); $Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance();

View File

@ -3,7 +3,7 @@ import axios from '../../../axios/axios';
// Actions related to background processes // Actions related to background processes
export const fetchProcesses = ({ commit }, {page, processesPerPage}) => { export const fetchProcesses = ({ commit }, {page, processesPerPage}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let endpoint = '/bg-processes?'; let endpoint = '/bg-processes?all_users=1';
if (page != undefined) if (page != undefined)
endpoint += 'paged=' + page; endpoint += 'paged=' + page;

View File

@ -227,49 +227,11 @@ export const deleteCollection = ({ commit }, { collectionId, isPermanently }) =>
export const updateCollection = ({ commit }, { export const updateCollection = ({ commit }, {
collection_id, collection_id,
name, collection
description,
slug,
status,
enable_cover_page,
cover_page_id,
moderators_ids,
parent,
enabled_view_modes,
default_view_mode,
comment_status,
allow_comments
}) => { }) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.patch('/collections/' + collection_id, { axios.tainacan.patch('/collections/' + collection_id, collection).then( res => {
name: name, commit('setCollection', collection);
description: description,
status: status,
slug: slug,
cover_page_id: "" + cover_page_id,
enable_cover_page: enable_cover_page,
moderators_ids: moderators_ids,
parent: parent,
enabled_view_modes: enabled_view_modes,
default_view_mode: default_view_mode,
comment_status: comment_status,
allow_comments: allow_comments
}).then( res => {
commit('setCollection', {
id: collection_id,
name: name,
description: description,
slug: slug,
status: status,
enable_cover_page: enable_cover_page,
cover_page_id: cover_page_id,
moderators_ids: moderators_ids,
parent: parent,
enabled_view_modes: enabled_view_modes,
default_view_mode: default_view_mode,
comment_status: comment_status,
allow_comments: allow_comments
});
commit('setCollectionName', res.data.name); commit('setCollectionName', res.data.name);
commit('setCollectionURL', res.data.url); commit('setCollectionURL', res.data.url);
resolve( res.data ); resolve( res.data );
@ -280,18 +242,16 @@ export const updateCollection = ({ commit }, {
}); });
}; };
export const sendCollection = ( { commit }, { name, description, status, mapper }) => { export const sendCollection = ( { commit }, collection) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
var param = { var param = collection;
name: name, param['mapper'] = null;
description: description, param[tainacan_plugin.exposer_mapper_param] = collection.mapper;
status: status,
};
param[tainacan_plugin.exposer_mapper_param] = mapper;
axios.tainacan.post('/collections/', param) axios.tainacan.post('/collections/', param)
.then( res => { .then( res => {
commit('setCollection', { name: name, description: description, status: status, mapper: mapper }); let collection = res.data;
resolve( res.data ); commit('setCollection', collection);
resolve( collection );
}) })
.catch(error => { .catch(error => {
reject( error.response ); reject( error.response );

View File

@ -92,12 +92,9 @@ export const fetchItemTitle = ({ commit }, id) => {
}); });
} }
export const sendItem = ( { commit }, { collection_id, status, comment_status }) => { export const sendItem = ( { commit }, item) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.post('/collection/'+ collection_id + '/items/', { axios.tainacan.post('/collection/'+ item.collection_id + '/items/', item)
status: status,
comment_status: comment_status
})
.then( res => { .then( res => {
commit('setItem', res.data); commit('setItem', res.data);
commit('setLastUpdated'); commit('setLastUpdated');
@ -109,13 +106,10 @@ export const sendItem = ( { commit }, { collection_id, status, comment_status })
}); });
}; };
export const updateItem = ({ commit }, { item_id, status, comment_status }) => { export const updateItem = ({ commit }, item) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.patch('/items/' + item_id, { axios.tainacan.patch('/items/' + item.id, item).then( res => {
status: status,
comment_status: comment_status
}).then( res => {
commit('setItem', res.data); commit('setItem', res.data);
commit('setLastUpdated'); commit('setLastUpdated');
resolve( res.data ); resolve( res.data );

View File

@ -4,13 +4,7 @@ import qs from 'qs'
// TAXONOMIES // TAXONOMIES
export const createTaxonomy = ({commit}, taxonomy) => { export const createTaxonomy = ({commit}, taxonomy) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.post('/taxonomies', { axios.tainacan.post('/taxonomies', taxonomy)
name: taxonomy.name,
description: taxonomy.description,
status: taxonomy.status,
slug: taxonomy.slug,
allow_insert: taxonomy.allowInsert
})
.then( res => { .then( res => {
let taxonomy = res.data; let taxonomy = res.data;
commit('setTaxonomy', taxonomy); commit('setTaxonomy', taxonomy);
@ -39,18 +33,10 @@ export const deleteTaxonomy = ({ commit }, { taxonomyId, isPermanently }) => {
export const updateTaxonomy = ({ commit }, taxonomy) => { export const updateTaxonomy = ({ commit }, taxonomy) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.patch(`/taxonomies/${taxonomy.taxonomyId}`, { axios.tainacan.patch(`/taxonomies/${taxonomy.taxonomyId}`, taxonomy)
name: taxonomy.name,
description: taxonomy.description,
status: taxonomy.status,
slug: taxonomy.slug ? taxonomy.slug : '',
allow_insert: taxonomy.allowInsert
})
.then( res => { .then( res => {
let taxonomy = res.data; let taxonomy = res.data;
commit('setTaxonomy', taxonomy); commit('setTaxonomy', taxonomy);
resolve( taxonomy ); resolve( taxonomy );
}) })
.catch(error => { .catch(error => {
@ -239,18 +225,13 @@ export const fetchChildTerms = ({ commit }, { parentId, taxonomyId, fetchOnly, s
}); });
}; };
export const sendChildTerm = ({ commit }, { taxonomyId, name, description, parent, headerImageId }) => { export const sendChildTerm = ({ commit }, { taxonomyId, term }) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.post(`/taxonomy/${taxonomyId}/terms/`, { axios.tainacan.post(`/taxonomy/${taxonomyId}/terms/`, term)
name: name,
description: description,
parent: parent,
header_image_id: headerImageId,
})
.then( res => { .then( res => {
let term = res.data; let newTerm = res.data;
commit('addChildTerm', {term: term, parent: parent }); commit('addChildTerm', {term: newTerm, parent: term.parent });
resolve( term ); resolve( newTerm );
}) })
.catch(error => { .catch(error => {
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors }); reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });
@ -258,17 +239,12 @@ export const sendChildTerm = ({ commit }, { taxonomyId, name, description, paren
}); });
}; };
export const updateChildTerm = ({ commit }, { taxonomyId, termId, name, description, parent, headerImageId, oldParent }) => { export const updateChildTerm = ({ commit }, { taxonomyId, term }) => {
return new Promise(( resolve, reject ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${termId}`, { axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${term.term_id}`, term)
name: name,
description: description,
parent: parent,
header_image_id: headerImageId,
})
.then( res => { .then( res => {
let term = res.data; let updatedTerm = res.data;
commit('updateChildTerm', { term: term, parent: parent, oldParent: oldParent }); commit('updateChildTerm', { term: updatedTerm, parent: updatedTerm.parent, oldParent: term.parent });
resolve( term ); resolve( term );
}) })
.catch(error => { .catch(error => {

View File

@ -279,6 +279,11 @@ class Migrations {
flush_rewrite_rules(false); flush_rewrite_rules(false);
} }
static function refresh_rewrite_rules_items() {
// needed after we added the /items rewrite rule
flush_rewrite_rules(false);
}
} }

View File

@ -50,6 +50,13 @@ class Theme_Helper {
add_shortcode( 'tainacan-search', array($this, 'search_shortcode')); add_shortcode( 'tainacan-search', array($this, 'search_shortcode'));
add_action( 'generate_rewrite_rules', array( &$this, 'rewrite_rules' ), 10, 1 );
add_filter( 'query_vars', array( &$this, 'rewrite_rules_query_vars' ) );
add_filter( 'template_include', array( &$this, 'rewrite_rule_template_include' ) );
add_action( 'pre_get_posts', array($this, 'archive_repository_pre_get_posts'));
// TODO: fix the WP Title
// add_filter( 'wp_title', array($this, 'archive_repository_wp_title'), 10, 3);
$this->register_view_mode('table', [ $this->register_view_mode('table', [
'label' => __('Table', 'tainacan'), 'label' => __('Table', 'tainacan'),
'dynamic_metadata' => true, 'dynamic_metadata' => true,
@ -112,7 +119,12 @@ class Theme_Helper {
if (in_array($current_post_type, $collections_post_types)) { if (in_array($current_post_type, $collections_post_types)) {
$title = sprintf( __( 'Collection: %s' ), post_type_archive_title( '', false ) ); $title = sprintf( __( 'Collection: %s' ), post_type_archive_title( '', false ) );
} }
} elseif (is_archive()) {
if (get_query_var('tainacan_repository_archive') == 1) {
$title = __( 'All items in repository', 'tainacan' );
} }
}
return $title; return $title;
} }
@ -325,6 +337,50 @@ class Theme_Helper {
} }
function rewrite_rules( &$wp_rewrite ) {
/* Translators: The Items slug - will be the URL for the repository archive */
$items_base = sanitize_title(_x('items', 'Slug: the string that will be used to build the URL to list all items of the repository', 'tainacan'));
$new_rules = array(
$items_base . "/?$" => "index.php?tainacan_repository_archive=1",
$items_base . "/page/([0-9]+)/?$" => 'index.php?tainacan_repository_archive=1&paged=$matches[1]'
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
function rewrite_rules_query_vars( $public_query_vars ) {
$public_query_vars[] = "tainacan_repository_archive";
return $public_query_vars;
}
function rewrite_rule_template_include( $template ) {
global $wp_query;
if ( $wp_query->get( 'tainacan_repository_archive' ) == 1 ) {
$templates = apply_filters('tainacan_repository_archive_template_hierarchy', ['tainacan/archive-repository.php', 'index.php']);
return locate_template($templates, false);
}
return $template;
}
function archive_repository_pre_get_posts($wp_query) {
if (!$wp_query->is_main_query() || $wp_query->get( 'tainacan_repository_archive' ) != 1)
return;
$wp_query->set( 'is_archive', true );
$wp_query->set( 'is_post_type_archive', false );
$wp_query->set( 'is_home', false );
$wp_query->is_home = false;
$wp_query->is_post_type_archive = false;
$wp_query->is_archive = true;
$wp_query->set( 'post_type', \Tainacan\Repositories\Repository::get_collections_db_identifiers() );
}
/** /**
* Register a new View Mode * Register a new View Mode
* *

View File

@ -1,3 +1,4 @@
<?php <?php
use \Tainacan\Entities; use \Tainacan\Entities;
@ -181,7 +182,6 @@ function tainacan_the_collection_description() {
function tainacan_the_faceted_search() { function tainacan_the_faceted_search() {
$props = ' '; $props = ' ';
$id = '';
// if in a collection page // if in a collection page
$collection_id = tainacan_get_collection_id(); $collection_id = tainacan_get_collection_id();
@ -190,7 +190,6 @@ function tainacan_the_faceted_search() {
$collection = new \Tainacan\Entities\Collection($collection_id); $collection = new \Tainacan\Entities\Collection($collection_id);
$props .= 'default-view-mode="' . $collection->get_default_view_mode() . '" '; $props .= 'default-view-mode="' . $collection->get_default_view_mode() . '" ';
$props .= 'enabled-view-modes="' . implode(',', $collection->get_enabled_view_modes()) . '" '; $props .= 'enabled-view-modes="' . implode(',', $collection->get_enabled_view_modes()) . '" ';
$id = 'tainacan-items-page';
} }
// if in a tainacan taxonomy // if in a tainacan taxonomy
@ -198,10 +197,9 @@ function tainacan_the_faceted_search() {
if ($term) { if ($term) {
$props .= 'term-id="' . $term->term_id . '" '; $props .= 'term-id="' . $term->term_id . '" ';
$props .= 'taxonomy="' . $term->taxonomy . '" '; $props .= 'taxonomy="' . $term->taxonomy . '" ';
$id = 'tainacan-items-page';
} }
echo "<div id='$id' $props ></div>"; echo "<div id='tainacan-items-page' $props ></div>";
} }