Fixes related items fetch for compound and other adjustments. #358

This commit is contained in:
mateuswetah 2021-07-02 16:26:55 -03:00
parent d455ccd9f0
commit b1087623a0
14 changed files with 38 additions and 35 deletions

View File

@ -122,7 +122,7 @@
color: var(--tainacan-block-gray5, #454647);
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
padding: 8px 12px;
display: block;
line-height: 1.2em;
word-break: break-word; }

View File

@ -129,7 +129,7 @@
color: var(--tainacan-block-gray5, #454647);
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
padding: 8px 12px;
display: block;
line-height: 1.2em;
word-break: break-word; }

View File

@ -1,5 +1,5 @@
.wp-block-tainacan-carousel-related-items {
margin: 2em auto;
margin: 0.5em auto;
width: 100%; }
.wp-block-tainacan-carousel-related-items .spinner-container {
min-height: 56px;

View File

@ -1,6 +1,6 @@
{
"version": 3,
"mappings": "AAEA,yCAA0C;EACtC,MAAM,EAAE,QAAQ;EAChB,KAAK,EAAE,IAAI;EAGX,4DAAmB;IACf,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,MAAM;IACvB,WAAW,EAAE,MAAM;IACnB,KAAK,EAAE,oCAAmC;AAI9C,qCAIC;EAHG,EAAE;IAAC,OAAO,EAAE,GAAG;EACf,GAAG;IAAC,OAAO,EAAE,GAAG;EAChB,IAAI;IAAC,OAAO,EAAE,GAAG;AAErB,kCAIC;EAHG,EAAE;IAAC,OAAO,EAAE,GAAG;EACf,GAAG;IAAC,OAAO,EAAE,GAAG;EAChB,IAAI;IAAC,OAAO,EAAE,GAAG;AAErB,gCAIC;EAHG,EAAE;IAAC,OAAO,EAAE,GAAG;EACf,GAAG;IAAC,OAAO,EAAE,GAAG;EAChB,IAAI;IAAC,OAAO,EAAE,GAAG;AAErB,6BAIC;EAHG,EAAE;IAAC,OAAO,EAAE,GAAG;EACf,GAAG;IAAC,OAAO,EAAE,GAAG;EAChB,IAAI;IAAC,OAAO,EAAE,GA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enberg-blocks/tainacan-items/carousel-related-items/carousel-related-items.scss"],
"names": [],
"file": "tainacan-gutenberg-block-carousel-related-items.css"

View File

@ -122,7 +122,7 @@
color: var(--tainacan-block-gray5, #454647);
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
padding: 8px 12px;
display: block;
line-height: 1.2em;
word-break: break-word; }

View File

@ -636,8 +636,8 @@ class Items extends Repository {
$response[$metadata->get_id() . '_' . $collection->get_id()] = array(
'collection_id' => $collection->get_id(),
'collection_name' => $collection->get_name(),
'url' => $collection->get_url(),
'slug' => $collection->get_slug(),
'collection_url' => $collection->get_url(),
'collection_slug' => $collection->get_slug(),
'metadata_id' => $metadata->get_id(),
'metadata_name' => $metadata->get_name(),
'total_items' => $related_items['found_posts'],
@ -651,8 +651,8 @@ class Items extends Repository {
$response[$metadata->get_id()] = array(
'collection_id' => $collection->get_id(),
'collection_name' => $collection->get_name(),
'url' => $collection->get_url(),
'slug' => $collection->get_slug(),
'collection_url' => $collection->get_url(),
'collection_slug' => $collection->get_slug(),
'metadata_id' => $metadata->get_id(),
'metadata_name' => $metadata->get_name(),
'total_items' => $related_items['found_posts'],

View File

@ -1695,7 +1695,7 @@ class Metadata extends Repository {
$order = ( is_array( $order ) ) ? $order : unserialize( $order );
if( is_array($order) ) {
foreach ($order as $metadata_order) {
if($metadata_order['id'] == $metadata->get_id()) {
if( $metadata_order['id'] == $metadata->get_id() || $metadata_order['id'] == $metadata->get_parent() ) {
if($metadata_order['enabled'] == false)
return false;
return true;

View File

@ -985,9 +985,9 @@ class Theme_Helper {
// Always pass the default class;
$output = '<div class="' . $args['class_name'] . ' wp-block-tainacan-carousel-related-items' . '">';
foreach($related_items as $collection_id => $related_group) {
if ( isset($related_group['items']) && isset($related_group['total_items']) && $related_group['total_items'] ) {
// Adds a heading with the collection name
@ -1014,24 +1014,27 @@ class Theme_Helper {
$carousel_div = $this->get_tainacan_items_carousel($carousel_args);
}
if ( $related_group['total_items'] > 1 ) {
$output .= '<div class="wp-block-group">
<div class="wp-block-group__inner-container">' .
$collection_heading .
$metadata_label .
$carousel_div .
'<div class="wp-block-buttons">
<div class="wp-block-button">
<a class="wp-block-button__link">
' . sprintf( __('View all (%s) related items', 'tainacan'), $related_group['total_items'] ) . '
</a>
</div>
</div>
<div style="height:70px" aria-hidden="true" class="wp-block-spacer">
</div>
$output .= '<div class="wp-block-group">
<div class="wp-block-group__inner-container">' .
$collection_heading .
$metadata_label .
$carousel_div .
(
$related_group['total_items'] > 1 ?
'<div class="wp-block-buttons">
<div class="wp-block-button">
<a class="wp-block-button__link" href="/' . $related_group['collection_slug'] . '?metaquery[0][key]=' . $related_group['metadata_id'] . '&metaquery[0][value][0]=' . $item->get_ID() . '&metaquery[0][compare]=IN">
' . sprintf( __('View all %s related items', 'tainacan'), $related_group['total_items'] ) . '
</a>
</div>
</div>'
: ''
)
. '<div style="height:30px" aria-hidden="true" class="wp-block-spacer">
</div>
</div>';
}
</div>
</div>';
}
}

View File

@ -1054,7 +1054,7 @@ function tainacan_has_related_items($item_id = false) {
return;
// Then fetches related ones
$related_items = $item->get_related_items();
$related_items = $item->get_related_items();// TODO: handle this inside the item so we don't have to load things here.
if ( !$related_items || !is_array($related_items) || !count($related_items) )
return false;

View File

@ -142,7 +142,7 @@
color: var(--tainacan-block-gray5, $gray5);
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
padding: 8px 12px;
display: block;
line-height: 1.2em;
word-break: break-word;

View File

@ -154,7 +154,7 @@
color: var(--tainacan-block-gray5, $gray5);
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
padding: 8px 12px;
display: block;
line-height: 1.2em;
word-break: break-word;

View File

@ -1,7 +1,7 @@
@import '../../gutenberg-blocks-variables.scss';
.wp-block-tainacan-carousel-related-items {
margin: 2em auto;
margin: 0.5em auto;
width: 100%;
// Spinner

View File

@ -165,7 +165,7 @@ registerBlockType('tainacan/carousel-related-items', {
],
[
'core/spacer',
{ height: 70 }
{ height: 30 }
]
]
]);

View File

@ -142,7 +142,7 @@
color: var(--tainacan-block-gray5, $gray5);
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
padding: 8px 12px;
display: block;
line-height: 1.2em;
word-break: break-word;