Merge branch 'develop' into feature/566
This commit is contained in:
commit
155d344bca
|
@ -14,7 +14,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
private $metadatum_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->rest_base = 'metadata';
|
||||
$this->rest_base = 'item';
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
* Both of GETs return the metadatum of matched objects
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base . '/(?P<metadatum_id>[\d]+)',
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<item_id>[\d]+)/metadata/(?P<metadatum_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
|
@ -60,7 +60,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base,
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<item_id>[\d]+)/metadata',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
|
@ -70,6 +70,15 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
)
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<item_id>[\d]+)/metadatasection/(?P<metadata_section_id>[\d|default_section]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,13 +124,27 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
public function get_items( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
|
||||
$args = array();
|
||||
if( isset($request['metadata_section_id']) ) {
|
||||
$args = array_merge($args, array(
|
||||
'parent' => 0,
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => 'metadata_section_id',
|
||||
'value' => $request['metadata_section_id'],
|
||||
'compare' => '='
|
||||
]
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
$item = $this->item_repository->fetch($item_id);
|
||||
|
||||
if( in_array($item->get_status(), ['auto-draft'] ) ) {
|
||||
$this->item_metadata_repository->create_default_value_metadata($item);
|
||||
}
|
||||
|
||||
$items_metadata = $item->get_metadata();
|
||||
$items_metadata = $item->get_metadata( $args );
|
||||
|
||||
$prepared_item = [];
|
||||
|
||||
|
|
|
@ -98,7 +98,10 @@ class Item_Metadata extends Repository {
|
|||
|
||||
if ( is_array( $item_metadata->get_value() ) ) {
|
||||
$values = $item_metadata->get_value();
|
||||
|
||||
// for relationship metadata do not allow the same item to be present more than once in the value.
|
||||
if ( $metadata_type->get_primitive_type() == 'item' ) {
|
||||
$values = array_unique($values);
|
||||
}
|
||||
foreach ( $values as $value ) {
|
||||
if ( !is_numeric($value) && empty($value) ) {
|
||||
continue;
|
||||
|
|
|
@ -1028,7 +1028,7 @@ class Theme_Helper {
|
|||
);
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
$props = ' ';
|
||||
|
||||
|
||||
// Always pass the class needed by Vue to mount the component;
|
||||
$args['class'] = $args['class_name'] . ' wp-block-tainacan-dynamic-items-list';
|
||||
unset($args['class_name']);
|
||||
|
@ -1054,6 +1054,7 @@ class Theme_Helper {
|
|||
* Optional. Array of arguments.
|
||||
* @type string $item_id The Item ID
|
||||
* @type string $items_list_layout The type of list to be rendered. Accepts 'grid', 'list', 'mosaic' and 'carousel'.
|
||||
* @type string $order Sorting direction to the related items query. Either 'desc' or 'asc'.
|
||||
* @type string $class_name Extra class to add to the wrapper, besides the default wp-block-tainacan-carousel-related-items
|
||||
* @type string $collection_heading_class_name Extra class to add to the collection name wrapper. Defaults to ''
|
||||
* @type string $collection_heading_tag Tag to be used as wrapper of the collection name. Defaults to h2
|
||||
|
@ -1081,7 +1082,11 @@ class Theme_Helper {
|
|||
return;
|
||||
|
||||
// Then fetches related ones
|
||||
$related_items = $item->get_related_items();
|
||||
$related_items_query_args = [];
|
||||
if ( isset($args['order']) )
|
||||
$related_items_query_args['order'] = $args['order'];
|
||||
|
||||
$related_items = $item->get_related_items($related_items_query_args);
|
||||
if (!count($related_items))
|
||||
return;
|
||||
|
||||
|
@ -1112,10 +1117,11 @@ class Theme_Helper {
|
|||
: $args['carousel_args'];
|
||||
|
||||
$no_crop_images_to_square = isset($block_args['crop_images_to_square']) && !$block_args['crop_images_to_square'];
|
||||
$image_size = isset($block_args['image_size'])
|
||||
$image_size = isset($block_args['image_size'])
|
||||
? $block_args['image_size']
|
||||
: ($no_crop_images_to_square ? 'tainacan-medium-full' : 'tainacan-medium');
|
||||
// remove attribute description and unused thumbnails image sizes, to avoid poluting HTML
|
||||
|
||||
// Remove attribute description and unused thumbnails image sizes, to avoid poluting HTML
|
||||
$related_group['items'] = array_map(
|
||||
function($el) use ($image_size) {
|
||||
$el['thumbnail'] = array_filter($el['thumbnail'], function($key) use ($image_size) {
|
||||
|
@ -1131,7 +1137,8 @@ class Theme_Helper {
|
|||
'collection_id' => $related_group['collection_id'],
|
||||
'load_strategy' => 'parent',
|
||||
'selected_items' => json_encode($related_group['items']),
|
||||
'layout' => $args['items_list_layout']
|
||||
'layout' => $args['items_list_layout'],
|
||||
'image_size' => $image_size
|
||||
], $block_args);
|
||||
|
||||
$items_list_div = $this->get_tainacan_dynamic_items_list($items_list_args);
|
||||
|
@ -1139,7 +1146,8 @@ class Theme_Helper {
|
|||
$items_list_args = wp_parse_args([
|
||||
'collection_id' => $related_group['collection_id'],
|
||||
'load_strategy' => 'parent',
|
||||
'selected_items' => json_encode($related_group['items'])
|
||||
'selected_items' => json_encode($related_group['items']),
|
||||
'image_size' => $image_size
|
||||
], $block_args);
|
||||
|
||||
$items_list_div = $this->get_tainacan_items_carousel($items_list_args);
|
||||
|
@ -1159,7 +1167,7 @@ class Theme_Helper {
|
|||
$related_group['total_items'] > 1 ?
|
||||
'<div class="wp-block-buttons">
|
||||
<div class="wp-block-button">
|
||||
<a class="wp-block-button__link" href="' . esc_url('/' . $related_group['collection_slug']) . '?metaquery[0][key]=' . esc_attr($related_group['metadata_id']) . '&metaquery[0][value][0]=' . esc_attr($item->get_ID()) . '&metaquery[0][compare]=IN">
|
||||
<a class="wp-block-button__link" href="' . esc_url( get_permalink( $related_group['collection_id'] ) ) . '?metaquery[0][key]=' . esc_attr($related_group['metadata_id']) . '&metaquery[0][value][0]=' . esc_attr($item->get_ID()) . '&metaquery[0][compare]=IN">
|
||||
' . sprintf( __('View all %s related items', 'tainacan'), $related_group['total_items'] ) . '
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -206,11 +206,11 @@
|
|||
:class="(!showName ? 'item-without-title' : '') + ' ' + (!showImage ? 'item-without-image' : '')">
|
||||
<blur-hash-image
|
||||
v-if="showImage"
|
||||
:height="$thumbHelper.getHeight(item['thumbnail'], ( layout == 'list' || imageSize ))"
|
||||
:width="$thumbHelper.getWidth(item['thumbnail'], ( layout == 'list' || imageSize ))"
|
||||
:src="$thumbHelper.getSrc(item['thumbnail'], ( layout == 'list' || imageSize ), item['document_mimetype'])"
|
||||
:srcset="$thumbHelper.getSrcSet(item['thumbnail'], ( layout == 'list' || imageSize ), item['document_mimetype'])"
|
||||
:hash="$thumbHelper.getBlurhashString(item['thumbnail'], ( layout == 'list' || imageSize ))"
|
||||
:height="$thumbHelper.getHeight(item['thumbnail'], imageSize)"
|
||||
:width="$thumbHelper.getWidth(item['thumbnail'], imageSize)"
|
||||
:src="$thumbHelper.getSrc(item['thumbnail'], imageSize, item['document_mimetype'])"
|
||||
:srcset="$thumbHelper.getSrcSet(item['thumbnail'], imageSize, item['document_mimetype'])"
|
||||
:hash="$thumbHelper.getBlurhashString(item['thumbnail'], imageSize)"
|
||||
:alt="item.thumbnail_alt ? item.thumbnail_alt : (item && item.name ? item.name : $root.__( 'Thumbnail', 'tainacan' ))"
|
||||
:transition-duration="500" />
|
||||
<span v-if="item.title">{{ item.title }}</span>
|
||||
|
@ -252,11 +252,11 @@
|
|||
:href="item.url"
|
||||
:class="(!showName ? 'item-without-title' : '') + ' ' + (!showImage ? 'item-without-image' : '')">
|
||||
<blur-hash-image
|
||||
:height="$thumbHelper.getHeight(item['thumbnail'], ( layout == 'list' || imageSize ))"
|
||||
:width="$thumbHelper.getWidth(item['thumbnail'], ( layout == 'list' || imageSize ))"
|
||||
:src="$thumbHelper.getSrc(item['thumbnail'], ( layout == 'list' || imageSize ), item['document_mimetype'])"
|
||||
:srcset="$thumbHelper.getSrcSet(item['thumbnail'], ( layout == 'list' || imageSize ), item['document_mimetype'])"
|
||||
:hash="$thumbHelper.getBlurhashString(item['thumbnail'], ( layout == 'list' || imageSize ))"
|
||||
:height="$thumbHelper.getHeight(item['thumbnail'], imageSize)"
|
||||
:width="$thumbHelper.getWidth(item['thumbnail'], imageSize)"
|
||||
:src="$thumbHelper.getSrc(item['thumbnail'], imageSize, item['document_mimetype'])"
|
||||
:srcset="$thumbHelper.getSrcSet(item['thumbnail'], imageSize, item['document_mimetype'])"
|
||||
:hash="$thumbHelper.getBlurhashString(item['thumbnail'], imageSize)"
|
||||
:alt="item.thumbnail_alt ? item.thumbnail_alt : (item && item.name ? item.name : $root.__( 'Thumbnail', 'tainacan' ))"
|
||||
:transition-duration="500" />
|
||||
<span v-if="item.title">{{ item.title }}</span>
|
||||
|
|
Loading…
Reference in New Issue