diff --git a/src/admin/components/edition/collection-edition-form.vue b/src/admin/components/edition/collection-edition-form.vue index ff9cb0180..0d46711cf 100644 --- a/src/admin/components/edition/collection-edition-form.vue +++ b/src/admin/components/edition/collection-edition-form.vue @@ -23,12 +23,12 @@
{{ $i18n.get('label_empty_thumbnail') }} + :src="(collection.thumbnail == undefined || collection.thumbnail == false) ? thumbPlaceholderPath : collection.thumbnail">
{ - this.collection.featured_image = false; + this.collection.thumbnail = false; }) .catch((error) => { this.$console.error(error); @@ -548,7 +548,7 @@ export default { onSave: (mediaId) => { this.updateThumbnail({collectionId: this.collectionId, thumbnailId: mediaId}) .then((res) => { - this.collection.featured_image = res.featured_image; + this.collection.thumbnail = res.thumbnail; }) .catch(error => this.$console.error(error)); } diff --git a/src/admin/components/edition/item-edition-form.vue b/src/admin/components/edition/item-edition-form.vue index 2a54a77e8..1a272297a 100644 --- a/src/admin/components/edition/item-edition-form.vue +++ b/src/admin/components/edition/item-edition-form.vue @@ -198,8 +198,8 @@ + :title="$i18n.getHelperTitle('items', '_thumbnail_id')" + :message="$i18n.getHelperMessage('items', '_thumbnail_id')"/>
{{ $i18n.get('label_empty_thumbnail') }} + :src="(item.thumbnail == undefined || item.thumbnail == false) ? thumbPlaceholderPath : item.thumbnail">
{ - this.item.featured_image = false; + this.item.thumbnail = false; }) .catch((error) => { this.$console.error(error); @@ -483,7 +483,7 @@ export default { onSave: (mediaId) => { this.updateThumbnail({itemId: this.itemId, thumbnailId: mediaId}) .then((res) => { - this.item.featured_image = res.featured_image; + this.item.thumbnail = res.thumbnail; }) .catch(error => this.$console.error(error)); } diff --git a/src/admin/components/lists/collections-list.vue b/src/admin/components/lists/collections-list.vue index 851922563..fd674da52 100644 --- a/src/admin/components/lists/collections-list.vue +++ b/src/admin/components/lists/collections-list.vue @@ -28,16 +28,16 @@ tabindex="0" :label="$i18n.get('label_thumbnail')" :aria-label="$i18n.get('label_thumbnail')" - field="featured_image" + field="thumbnail" width="55"> diff --git a/src/admin/components/other/event/diff-exhibition/event-split.vue b/src/admin/components/other/event/diff-exhibition/event-split.vue index b4e2c630e..779e81a0e 100644 --- a/src/admin/components/other/event/diff-exhibition/event-split.vue +++ b/src/admin/components/other/event/diff-exhibition/event-split.vue @@ -13,7 +13,7 @@

{{ `${key.replace('_', ' ')}:` }}
-
+
@@ -81,7 +81,7 @@ :class="{ 'has-text-success': !diff.old, 'back-hlight': !diff.old }"> {{ `${key.replace('_', ' ')}:` }}
-
+
diff --git a/src/admin/components/other/event/diff-exhibition/event-unified.vue b/src/admin/components/other/event/diff-exhibition/event-unified.vue index 1302d62b4..d426558dc 100644 --- a/src/admin/components/other/event/diff-exhibition/event-unified.vue +++ b/src/admin/components/other/event/diff-exhibition/event-unified.vue @@ -14,7 +14,7 @@

{{ `${key.replace('_', ' ')}:` }}
-
+
@@ -79,7 +79,7 @@ :class="{ 'has-text-success': !diff.old, 'back-hlight': !diff.old }"> {{ `${key.replace('_', ' ')}:` }}
-
+
diff --git a/src/admin/components/other/event/unique-exhibition/event-nodiff.vue b/src/admin/components/other/event/unique-exhibition/event-nodiff.vue index 6b121d915..9bf435297 100644 --- a/src/admin/components/other/event/unique-exhibition/event-nodiff.vue +++ b/src/admin/components/other/event/unique-exhibition/event-nodiff.vue @@ -16,7 +16,7 @@
{{ `${key.replace('_', ' ')}:` }}
-
+
diff --git a/src/admin/pages/lists/events-page.vue b/src/admin/pages/lists/events-page.vue index 954c967c1..776fcdfa1 100644 --- a/src/admin/pages/lists/events-page.vue +++ b/src/admin/pages/lists/events-page.vue @@ -5,7 +5,7 @@ 'primary-page': isRepositoryLevel, 'page-container': isRepositoryLevel }"> - +
diff --git a/src/admin/pages/lists/items-page.vue b/src/admin/pages/lists/items-page.vue index c5aaa929f..aa05e55f4 100644 --- a/src/admin/pages/lists/items-page.vue +++ b/src/admin/pages/lists/items-page.vue @@ -28,6 +28,7 @@

{{ $i18n.get('filters') }}

{{ collapseAll ? $i18n.get('label_collapse_all') : $i18n.get('label_expand_all') }} @@ -233,7 +234,7 @@ name: this.$i18n.get('label_thumbnail'), field: 'row_thumbnail', field_type: undefined, - slug: 'featured_image', + slug: 'thumbnail', id: undefined, display: true }); diff --git a/src/admin/pages/singles/item-page.vue b/src/admin/pages/singles/item-page.vue index 1317e816f..7a70c952a 100644 --- a/src/admin/pages/singles/item-page.vue +++ b/src/admin/pages/singles/item-page.vue @@ -22,12 +22,12 @@

- +

diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index a597fbfae..40fcdede9 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -12,7 +12,7 @@ class Collection extends Entity { protected $diplay_name, $full, - $featured_img_id, + $_thumbnail_id, $modification_date, $creation_date, $author_id, @@ -68,7 +68,7 @@ class Collection extends Entity { public function __toArray() { $array_collection = parent::__toArray(); - $array_collection['featured_image'] = $this->get_featured_image(); + $array_collection['thumbnail'] = $this->get_thumbnail(); $array_collection['header_image'] = $this->get_header_image(); $array_collection['author_name'] = $this->get_author_name(); @@ -204,7 +204,7 @@ class Collection extends Entity { /** * @return false|string */ - function get_featured_image() { + function get_thumbnail() { return get_the_post_thumbnail_url( $this->get_id(), 'full' ); } @@ -218,18 +218,18 @@ class Collection extends Entity { /** * @param $id */ - function set_featured_img_id( $id ) { - $this->set_mapped_property( 'featured_img_id', $id ); + function set__thumbnail_id( $id ) { + $this->set_mapped_property( '_thumbnail_id', $id ); } /** * @return int|string */ - function get_featured_img_id() { - $featured_img_id = $this->get_mapped_property("featured_img_id"); - if ( isset( $featured_img_id ) ) { - return $featured_img_id; + function get__thumbnail_id() { + $_thumbnail_id = $this->get_mapped_property("_thumbnail_id"); + if ( isset( $_thumbnail_id ) ) { + return $_thumbnail_id; } return get_post_thumbnail_id( $this->get_id() ); diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index f5d68a193..cdfceccd5 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -13,7 +13,7 @@ class Item extends Entity { $terms, $diplay_name, $full, - $featured_img_id, + $_thumbnail_id, $modification_date, $creation_date, $author_id, @@ -52,8 +52,8 @@ class Item extends Entity { public function __toArray() { $array_item = parent::__toArray(); - $array_item['featured_image'] = $this->get_featured_image(); - $array_item['featured_img_id'] = $this->get_featured_img_id(); + $array_item['thumbnail'] = $this->get_thumbnail(); + $array_item['_thumbnail_id'] = $this->get__thumbnail_id(); $array_item['author_name'] = $this->get_author_name(); return $array_item; @@ -125,24 +125,24 @@ class Item extends Entity { /** * @return false|string */ - function get_featured_image() { + function get_thumbnail() { return get_the_post_thumbnail_url( $this->get_id(), 'full' ); } /** * @param $id */ - function set_featured_img_id( $id ) { - $this->set_mapped_property( 'featured_img_id', $id ); + function set__thumbnail_id( $id ) { + $this->set_mapped_property( '_thumbnail_id', $id ); } /** * @return int|string */ - function get_featured_img_id() { - $featured_img_id = $this->get_mapped_property("featured_img_id"); - if ( isset( $featured_img_id ) ) { - return $featured_img_id; + function get__thumbnail_id() { + $_thumbnail_id = $this->get_mapped_property("_thumbnail_id"); + if ( isset( $_thumbnail_id ) ) { + return $_thumbnail_id; } return get_post_thumbnail_id( $this->get_id() ); diff --git a/src/classes/filter-types/filter-types-mixin.js b/src/classes/filter-types/filter-types-mixin.js index f607d97b5..001ec4048 100644 --- a/src/classes/filter-types/filter-types-mixin.js +++ b/src/classes/filter-types/filter-types-mixin.js @@ -40,7 +40,7 @@ export const filter_type_mixin = { .then(res => { if (res.data.length > 0) { for (let item of res.data) { - this.options.push({label: item.title, value: item.id, img: item.featured_image }); + this.options.push({label: item.title, value: item.id, img: item.thumbnail }); } } }) diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index 8a0d4e14a..291e96877 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -186,7 +186,7 @@ class Collections extends Repository { 'description' => __( 'The IDs of users assigned as moderators of this collection', 'tainacan' ), 'validation' => '' ], - 'featured_img_id' => [ + '_thumbnail_id' => [ 'map' => 'meta', 'title' => __( 'Featured image ID', 'tainacan' ), 'description' => __( 'Featured image ID', 'tainacan' ) diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index a68e27d27..790089013 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -106,7 +106,7 @@ class Items extends Repository { 'on_error' => __( 'Invalid document', 'tainacan' ), 'default' => '' ], - 'featured_img_id' => [ + '_thumbnail_id' => [ 'map' => 'meta', 'title' => __( 'Featured image ID', 'tainacan' ), 'description' => __( 'Featured image ID', 'tainacan' ) diff --git a/src/classes/repositories/class-tainacan-logs.php b/src/classes/repositories/class-tainacan-logs.php index df600c391..679492c5c 100644 --- a/src/classes/repositories/class-tainacan-logs.php +++ b/src/classes/repositories/class-tainacan-logs.php @@ -312,20 +312,20 @@ class Logs extends Repository { if ( $is_update ) { $msn = $this->prepare_event_message($class_name, 'updated'); - $description = $this->prepare_description_message($new_value, $name, $class_name, 'updated'); + $description = $this->prepare_event_description_message($new_value, $name, $class_name, 'updated'); } elseif( $is_delete ){ // was deleted $msn = $this->prepare_event_message($class_name, 'deleted'); - $description = $this->prepare_description_message($new_value, $name, $class_name, 'deleted'); + $description = $this->prepare_event_description_message($new_value, $name, $class_name, 'deleted'); } elseif( !empty($diffs) ) { // was created $msn = $this->prepare_event_message($class_name, 'created'); - $description = $this->prepare_description_message($new_value, $name, $class_name, 'created'); + $description = $this->prepare_event_description_message($new_value, $name, $class_name, 'created'); } elseif( $is_trash ) { // was trashed $msn = $this->prepare_event_message($class_name, 'trashed'); - $description = $this->prepare_description_message($new_value, $name, $class_name, 'trashed'); + $description = $this->prepare_event_description_message($new_value, $name, $class_name, 'trashed'); } $msn = apply_filters( 'tainacan-insert-log-message-title', $msn, $type, $new_value ); @@ -363,7 +363,7 @@ class Logs extends Repository { * * @return string */ - private function prepare_description_message($object, $name, $class_name, $action_message){ + private function prepare_event_description_message($object, $name, $class_name, $action_message){ if ( $object instanceof Entities\Field || $object instanceof Entities\Item || $object instanceof Entities\Filter) { $collection = $object->get_collection(); $parent = $collection; diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index b56f52274..8126b205a 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -129,12 +129,10 @@ abstract class Repository { // Now run through properties stored as postmeta foreach ( $map as $prop => $mapped ) { if ( $mapped['map'] == 'meta' || $mapped['map'] == 'meta_multi' ) { - $this->insert_metadata( $obj, $prop ); + $diffs = $this->insert_metadata( $obj, $prop, $diffs ); } } - $diffs = $this->insert_thumbnail( $obj, $diffs ); - // TODO: Logs for header image insert and update do_action( 'tainacan-insert', $obj, $diffs, $is_update ); @@ -150,9 +148,11 @@ abstract class Repository { * @param \Tainacan\Entities $obj The entity object * @param string $prop the property name, as declared in the map of the repository * + * @param $diffs + * * @return null|false on error */ - public function insert_metadata( $obj, $prop ) { + public function insert_metadata( $obj, $prop, $diffs ) { $map = $this->get_map(); if ( ! array_key_exists( $prop, $map ) ) { @@ -160,16 +160,26 @@ abstract class Repository { } if ( $map[ $prop ]['map'] == 'meta' ) { - update_post_meta( $obj->get_id(), $prop, $this->maybe_add_slashes( $obj->get_mapped_property( $prop ) ) ); + + if($prop === '_thumbnail_id'){ + $diffs = $this->insert_thumbnail($obj, $diffs); + + return $diffs; + } else { + update_post_meta( $obj->get_id(), $prop, $this->maybe_add_slashes( $obj->get_mapped_property( $prop ) ) ); + } + } elseif ( $map[ $prop ]['map'] == 'meta_multi' ) { $values = $obj->get_mapped_property( $prop ); $current_values = get_post_meta( $obj->get_id(), $prop ); - if (empty($values) || !is_array($values)) + if (empty($values) || !is_array($values)) { $values = []; - - if (empty($current_values) || !is_array($current_values)) + } + + if (empty($current_values) || !is_array($current_values)) { $current_values = []; + } $deleted = array_diff( $current_values, $values ); $added = array_diff( $values, $current_values ); @@ -183,6 +193,8 @@ abstract class Repository { } } + + return $diffs; } function maybe_add_slashes( $value ) { @@ -710,61 +722,62 @@ abstract class Repository { } } - unset($diff['id'], $diff['collection_id'], $diff['author_id'], $diff['creation_date'], $diff['featured_img_id']); + unset($diff['id'], $diff['collection_id'], $diff['author_id'], $diff['creation_date'], $diff['_thumbnail_id']); $diff = apply_filters( 'tainacan-entity-diff', $diff, $new, $old ); return $diff; } /** + * Inserts or update thumbnail for items and collections and return an array + * with old thumbnail and new thumbnail + * * @param $obj * @param $diffs * * @return mixed */ - protected function insert_thumbnail( $obj, $diffs ) { - if ( method_exists( $obj, 'get_featured_img_id' ) ) { - if ( ! get_post_thumbnail_id( $obj->WP_Post->ID ) ) { - // was added a thumbnail + private function insert_thumbnail( $obj, $diffs ) { + if ( ! get_post_thumbnail_id( $obj->WP_Post->ID ) ) { + // was added a thumbnail - $settled = set_post_thumbnail( $obj->WP_Post, (int) $obj->get_featured_img_id() ); + $settled = set_post_thumbnail( $obj->WP_Post, (int) $obj->get__thumbnail_id() ); - if ( $settled ) { + if ( $settled ) { - $thumbnail_url = get_the_post_thumbnail_url( $obj->WP_Post->ID ); + $thumbnail_url = get_the_post_thumbnail_url( $obj->WP_Post->ID ); - $diffs['featured_image'] = [ - 'new' => $thumbnail_url, - 'old' => '', - 'diff_with_index' => 0, - ]; + $diffs['thumbnail'] = [ + 'new' => $thumbnail_url, + 'old' => '', + 'diff_with_index' => 0, + ]; - } + } + } else { + + // was updated a thumbnail + + $old_thumbnail = get_the_post_thumbnail_url( $obj->WP_Post->ID ); + + $fid = $obj->get__thumbnail_id(); + + if ( ! $fid ) { + $settled = delete_post_thumbnail( $obj->WP_Post ); } else { + $settled = set_post_thumbnail( $obj->WP_Post, (int) $fid ); + } - // was update a thumbnail + if ( $settled ) { - $old_thumbnail = get_the_post_thumbnail_url( $obj->WP_Post->ID ); + $thumbnail_url = get_the_post_thumbnail_url( $obj->WP_Post->ID ); - $fid = $obj->get_featured_img_id(); - - if ( ! $fid ) { - $settled = delete_post_thumbnail( $obj->WP_Post ); - } else { - $settled = set_post_thumbnail( $obj->WP_Post, (int) $fid ); - } - - if ( $settled ) { - - $thumbnail_url = get_the_post_thumbnail_url( $obj->WP_Post->ID ); - - $diffs['featured_image'] = [ - 'new' => $thumbnail_url, - 'old' => $old_thumbnail, - 'diff_with_index' => 0, - ]; - } + $diffs['thumbnail'] = [ + 'new' => $thumbnail_url, + 'old' => $old_thumbnail, + 'diff_with_index' => 0, + ]; } } diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js index d0c9c3098..66afa737c 100644 --- a/src/js/store/modules/collection/actions.js +++ b/src/js/store/modules/collection/actions.js @@ -194,7 +194,7 @@ export const fetchAttachments = ({ commit }, collection_id) => { export const updateThumbnail = ({ commit }, { collectionId, thumbnailId }) => { return new Promise((resolve, reject) => { axios.tainacan.patch('/collections/' + collectionId, { - featured_img_id: thumbnailId + _thumbnail_id: thumbnailId }).then( res => { let collection = res.data commit('setCollection', collection); diff --git a/src/js/store/modules/item/actions.js b/src/js/store/modules/item/actions.js index 42953a854..a4c26df7b 100644 --- a/src/js/store/modules/item/actions.js +++ b/src/js/store/modules/item/actions.js @@ -164,7 +164,7 @@ export const fetchAttachments = ({ commit }, item_id) => { export const updateThumbnail = ({ commit }, { itemId, thumbnailId }) => { return new Promise((resolve, reject) => { axios.tainacan.patch('/items/' + itemId, { - featured_img_id: thumbnailId + _thumbnail_id: thumbnailId }).then( res => { let item = res.data commit('setItem', item);