Begins conversion of save functions to php side. #566.
This commit is contained in:
parent
19f2f83e78
commit
b70b35fd1c
|
@ -0,0 +1,51 @@
|
|||
.wp-block-tainacan-related-items {
|
||||
margin: 0.5em auto;
|
||||
width: 100%; }
|
||||
.wp-block-tainacan-related-items .spinner-container {
|
||||
min-height: 56px;
|
||||
padding: 1em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: var(--tainacan-block-gray4, #555758); }
|
||||
@-webkit-keyframes skeleton-animation {
|
||||
0% {
|
||||
opacity: 1.0; }
|
||||
50% {
|
||||
opacity: 0.2; }
|
||||
100% {
|
||||
opacity: 1.0; } }
|
||||
@-moz-keyframes skeleton-animation {
|
||||
0% {
|
||||
opacity: 1.0; }
|
||||
50% {
|
||||
opacity: 0.2; }
|
||||
100% {
|
||||
opacity: 1.0; } }
|
||||
@-o-keyframes skeleton-animation {
|
||||
0% {
|
||||
opacity: 1.0; }
|
||||
50% {
|
||||
opacity: 0.2; }
|
||||
100% {
|
||||
opacity: 1.0; } }
|
||||
@keyframes skeleton-animation {
|
||||
0% {
|
||||
opacity: 1.0; }
|
||||
50% {
|
||||
opacity: 0.2; }
|
||||
100% {
|
||||
opacity: 1.0; } }
|
||||
.wp-block-tainacan-related-items .skeleton {
|
||||
border-radius: 2px;
|
||||
background: var(--tainacan-block-gray1, #f2f2f2);
|
||||
-webkit-animation: skeleton-animation 1.8s ease infinite;
|
||||
-moz-animation: skeleton-animation 1.8s ease infinite;
|
||||
-o-animation: skeleton-animation 1.8s ease infinite;
|
||||
animation: skeleton-animation 1.8s ease infinite; }
|
||||
.wp-block-tainacan-related-items .related-items-edit-container {
|
||||
position: relative; }
|
||||
.wp-block-tainacan-related-items .related-items-edit-container .skeleton {
|
||||
min-height: 150px; }
|
||||
|
||||
/*# sourceMappingURL=tainacan-gutenberg-block-metadata-section-description.css.map */
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"version": 3,
|
||||
"mappings": "AAEA,gCAAiC;EAC7B,MAAM,EAAE,UAAU;EAClB,KAAK,EAAE,IAAI;EAGX,mDAAmB;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,GAAG;EAErB,0CAAU;IACN,aAAa,EAAE,GAAG;IAClB,UAAU,EAAE,oCAAmC;IAE/C,iBAAiB,EAAE,qCAAqC;IACxD,cAAc,EAAE,qCAAqC;IACrD,YAAY,EAAE,qCAAqC;IACnD,SAAS,EAAE,qCAAqC;EAIpD,8DAA8B;IAC1B,QAAQ,EAAE,QAAQ;IAElB,wEAAY;MACR,UAAU,EAAE,KAAK",
|
||||
"sources": ["../../views/gutenberg-blocks/blocks/related-items-list/style.scss"],
|
||||
"names": [],
|
||||
"file": "tainacan-gutenberg-block-metadata-section-description.css"
|
||||
}
|
|
@ -26,6 +26,10 @@
|
|||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"isDynamic": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"collectionId": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
const { __ } = wp.i18n;
|
||||
|
||||
const { Button, Spinner, Placeholder } = wp.components;
|
||||
const { Button, Spinner, Placeholder, ToggleControl, PanelBody } = wp.components;
|
||||
|
||||
const { useBlockProps, InnerBlocks } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
|
||||
const ServerSideRender = wp.serverSideRender;
|
||||
const { useBlockProps, InnerBlocks, InspectorControls } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
|
||||
|
||||
import SingleItemMetadataSectionModal from '../../js/selection/single-item-metadata-section-modal.js';
|
||||
import getCollectionIdFromPossibleTemplateEdition from '../../js/template/tainacan-blocks-single-item-template-mode.js';
|
||||
|
@ -24,11 +25,13 @@ export default function ({ attributes, setAttributes, className, isSelected }) {
|
|||
sectionMetadata,
|
||||
metadataSectionTemplate,
|
||||
dataSource,
|
||||
templateMode
|
||||
templateMode,
|
||||
isDynamic
|
||||
} = attributes;
|
||||
|
||||
// Gets blocks props from hook
|
||||
const blockProps = tainacan_blocks.wp_version < '5.6' ? { className: className } : useBlockProps();
|
||||
const currentWPVersion = (typeof tainacan_blocks != 'undefined') ? tainacan_blocks.wp_version : tainacan_plugin.wp_version;
|
||||
|
||||
function setContent() {
|
||||
|
||||
|
@ -160,6 +163,24 @@ export default function ({ attributes, setAttributes, className, isSelected }) {
|
|||
: (
|
||||
<div { ...blockProps }>
|
||||
|
||||
<InspectorControls>
|
||||
<PanelBody
|
||||
title={ __('Data source', 'tainacan') }
|
||||
initialOpen={ true }
|
||||
>
|
||||
<ToggleControl
|
||||
label={ __('Dynamic sync from Tainacan', 'tainacan') }
|
||||
help={ __( 'Check this if you want the item metadata and section values to be always sync with its source from Tainacan. If disabled, however, you will be able to change order of inner blocks, delete and wrap them inside other blocks.', 'tainacan' ) }
|
||||
checked={ isDynamic }
|
||||
onChange={ ( isChecked ) => {
|
||||
isDynamic = isChecked;
|
||||
setAttributes({ isDynamic: isDynamic });
|
||||
}
|
||||
}
|
||||
/>
|
||||
</PanelBody>
|
||||
</InspectorControls>
|
||||
|
||||
{ isSelected ?
|
||||
(
|
||||
<div>
|
||||
|
@ -239,10 +260,18 @@ export default function ({ attributes, setAttributes, className, isSelected }) {
|
|||
</div> :
|
||||
<div className={ 'item-metadata-sections-edit-container' }>
|
||||
{ metadataSectionTemplate.length ?
|
||||
<InnerBlocks
|
||||
allowedBlocks={ true }
|
||||
template={ metadataSectionTemplate }
|
||||
templateInsertUpdatesSelection={ true } />
|
||||
( isDynamic ?
|
||||
<ServerSideRender
|
||||
block="tainacan/item-metadata-section"
|
||||
attributes={ attributes }
|
||||
httpMethod={ currentWPVersion >= '5.5' ? 'POST' : 'GET' }
|
||||
/>
|
||||
:
|
||||
<InnerBlocks
|
||||
allowedBlocks={ true }
|
||||
template={ metadataSectionTemplate }
|
||||
templateInsertUpdatesSelection={ true } />
|
||||
)
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { useBlockProps, InnerBlocks } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
|
||||
|
||||
export default function({ className }) {
|
||||
export default function({ attributes, className }) {
|
||||
const blockProps = tainacan_blocks.wp_version < '5.6' ? { className: className } : useBlockProps.save();
|
||||
|
||||
return <div { ...blockProps }><InnerBlocks.Content /></div>
|
||||
return attributes.isDynamic ? null : <div { ...blockProps }><InnerBlocks.Content /></div>
|
||||
};
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Renders the content of the item metadata section
|
||||
* using Tainacan template functions
|
||||
*/
|
||||
function tainacan_blocks_render_metadata_section( $block_attributes, $content, $block ) {
|
||||
|
||||
$is_dynamic = isset($block_attributes['isDynamic']) ? ($block_attributes['isDynamic'] === 'true' || $block_attributes['isDynamic'] == 1) : false;
|
||||
|
||||
if ( $is_dynamic) {
|
||||
|
||||
// Basic check, otherwise we don't have nothing to render here.
|
||||
$item_id = !empty($block->context['tainacan/itemId']) ? $block->context['tainacan/itemId'] : (isset($block_attributes['itemId']) ? $block_attributes['itemId'] : false);
|
||||
$collection_id = isset($block_attributes['collectionId']) ? $block_attributes['collectionId'] : false;
|
||||
$section_id = isset($block_attributes['sectionId']) ? $block_attributes['sectionId'] : false;
|
||||
$template_mode = isset($block_attributes['templateMode']) ? $block_attributes['templateMode'] : false;
|
||||
|
||||
// Builds args from backend query
|
||||
$args = [
|
||||
'metadata_section' => $section_id
|
||||
];
|
||||
|
||||
// Checks if we are in the edit page or in the published
|
||||
$current_post = get_post();
|
||||
|
||||
if ( $template_mode && $collection_id ) {
|
||||
$collection_pt_pattern = '/' . \Tainacan\Entities\Collection::$db_identifier_prefix . '\d+' . \Tainacan\Entities\Collection::$db_identifier_sufix . '/';
|
||||
|
||||
if ( $current_post === NULL )
|
||||
return \Tainacan\Theme_Helper::get_instance()->get_tainacan_item_metadata_template( [], $collection_id );
|
||||
else if ( $current_post->post_type !== false && preg_match($collection_pt_pattern, $current_post->post_type) )
|
||||
return tainacan_get_the_metadata_sections( $args, $current_post->ID );
|
||||
|
||||
} else if ( $item_id ) {
|
||||
return tainacan_get_the_metadata_sections( $args, $item_id );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$inner_blocks = $block->inner_blocks;
|
||||
$inner_blocks_html = '';
|
||||
foreach ( $inner_blocks as $inner_block ) {
|
||||
$inner_blocks_html .= $inner_block->render();
|
||||
}
|
||||
return $inner_blocks_html;
|
||||
}
|
||||
}
|
|
@ -18,14 +18,14 @@
|
|||
"source": "query",
|
||||
"selector": "div"
|
||||
},
|
||||
"dataSource": {
|
||||
"type": "string",
|
||||
"default": "selection"
|
||||
},
|
||||
"templateMode": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"isDynamic": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"collectionId": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
@ -41,7 +41,7 @@
|
|||
"default": false
|
||||
},
|
||||
"metadataSectionsRequestSource": {
|
||||
"type": "string",
|
||||
"type": "object",
|
||||
"default": ""
|
||||
},
|
||||
"metadataSections": {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
const { __ } = wp.i18n;
|
||||
|
||||
const { Button, Spinner, Placeholder } = wp.components;
|
||||
const { Button, Spinner, Placeholder, ToggleControl, PanelBody } = wp.components;
|
||||
|
||||
const { useBlockProps, InnerBlocks } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
|
||||
const ServerSideRender = wp.serverSideRender;
|
||||
const { useBlockProps, InnerBlocks, InspectorControls } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
|
||||
|
||||
import SingleItemModal from '../../js/selection/single-item-modal.js';
|
||||
import getCollectionIdFromPossibleTemplateEdition from '../../js/template/tainacan-blocks-single-item-template-mode.js';
|
||||
|
@ -20,12 +21,13 @@ export default function ({ attributes, setAttributes, className, isSelected }) {
|
|||
isModalOpen,
|
||||
metadataSections,
|
||||
metadataSectionsTemplate,
|
||||
dataSource,
|
||||
templateMode
|
||||
templateMode,
|
||||
isDynamic
|
||||
} = attributes;
|
||||
|
||||
// Gets blocks props from hook
|
||||
const blockProps = tainacan_blocks.wp_version < '5.6' ? { className: className } : useBlockProps();
|
||||
const currentWPVersion = (typeof tainacan_blocks != 'undefined') ? tainacan_blocks.wp_version : tainacan_plugin.wp_version;
|
||||
|
||||
function setContent() {
|
||||
|
||||
|
@ -119,6 +121,24 @@ export default function ({ attributes, setAttributes, className, isSelected }) {
|
|||
: (
|
||||
<div { ...blockProps }>
|
||||
|
||||
<InspectorControls>
|
||||
<PanelBody
|
||||
title={ __('Data source', 'tainacan') }
|
||||
initialOpen={ true }
|
||||
>
|
||||
<ToggleControl
|
||||
label={ __('Dynamic sync from Tainacan', 'tainacan') }
|
||||
help={ __( 'Check this if you want the item metadata and section values to be always sync with its source from Tainacan. If disabled, however, you will be able to change order of inner blocks, delete and wrap them inside other blocks.', 'tainacan' ) }
|
||||
checked={ isDynamic }
|
||||
onChange={ ( isChecked ) => {
|
||||
isDynamic = isChecked;
|
||||
setAttributes({ isDynamic: isDynamic });
|
||||
}
|
||||
}
|
||||
/>
|
||||
</PanelBody>
|
||||
</InspectorControls>
|
||||
|
||||
{ isSelected ?
|
||||
(
|
||||
<div>
|
||||
|
@ -191,9 +211,17 @@ export default function ({ attributes, setAttributes, className, isSelected }) {
|
|||
</div> :
|
||||
<div className={ 'item-metadata-sections-edit-container' }>
|
||||
{ metadataSectionsTemplate.length ?
|
||||
<InnerBlocks
|
||||
allowedBlocks={ true }
|
||||
template={ metadataSectionsTemplate } />
|
||||
( isDynamic ?
|
||||
<ServerSideRender
|
||||
block="tainacan/item-metadata-sections"
|
||||
attributes={ attributes }
|
||||
httpMethod={ currentWPVersion >= '5.5' ? 'POST' : 'GET' }
|
||||
/>
|
||||
:
|
||||
<InnerBlocks
|
||||
allowedBlocks={ true }
|
||||
template={ metadataSectionsTemplate } />
|
||||
)
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { useBlockProps, InnerBlocks } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor );
|
||||
|
||||
export default function({ className }) {
|
||||
export default function({ attributes, className }) {
|
||||
const blockProps = tainacan_blocks.wp_version < '5.6' ? { className: className } : useBlockProps.save();
|
||||
|
||||
return <div { ...blockProps }><InnerBlocks.Content /></div>
|
||||
return attributes.isDynamic ? null : <div { ...blockProps }><InnerBlocks.Content /></div>
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Renders the content of the item metadata sections
|
||||
* using Tainacan template functions
|
||||
*/
|
||||
function tainacan_blocks_render_metadata_sections( $block_attributes, $content, $block ) {
|
||||
|
||||
$is_dynamic = isset($block_attributes['isDynamic']) ? ($block_attributes['isDynamic'] === 'true' || $block_attributes['isDynamic'] == 1) : false;
|
||||
|
||||
if ( $is_dynamic) {
|
||||
|
||||
// Basic check, otherwise we don't have nothing to render here.
|
||||
$item_id = !empty($block->context['tainacan/itemId']) ? $block->context['tainacan/itemId'] : (isset($block_attributes['itemId']) ? $block_attributes['itemId'] : false);
|
||||
$collection_id = isset($block_attributes['collectionId']) ? $block_attributes['collectionId'] : false;
|
||||
$template_mode = isset($block_attributes['templateMode']) ? $block_attributes['templateMode'] : false;
|
||||
|
||||
// Builds args from backend query
|
||||
$args = [];
|
||||
|
||||
// Checks if we are in the edit page or in the published
|
||||
$current_post = get_post();
|
||||
|
||||
if ( $template_mode && $collection_id ) {
|
||||
$collection_pt_pattern = '/' . \Tainacan\Entities\Collection::$db_identifier_prefix . '\d+' . \Tainacan\Entities\Collection::$db_identifier_sufix . '/';
|
||||
|
||||
if ( $current_post === NULL )
|
||||
return \Tainacan\Theme_Helper::get_instance()->get_tainacan_item_metadata_template( [], $collection_id );
|
||||
else if ( $current_post->post_type !== false && preg_match($collection_pt_pattern, $current_post->post_type) )
|
||||
return tainacan_get_the_metadata_sections( $args, $current_post->ID );
|
||||
|
||||
} else if ( $item_id ) {
|
||||
return tainacan_get_the_metadata_sections( $args, $item_id );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$inner_blocks = $block->inner_blocks;
|
||||
$inner_blocks_html = '';
|
||||
foreach ( $inner_blocks as $inner_block ) {
|
||||
$inner_blocks_html .= $inner_block->render();
|
||||
}
|
||||
return $inner_blocks_html;
|
||||
}
|
||||
}
|
|
@ -17,8 +17,8 @@ const TAINACAN_BLOCKS = [
|
|||
'faceted-search' => [],
|
||||
'item-submission-form' => [],
|
||||
'item-gallery' => ['render_callback' => 'tainacan_blocks_render_items_gallery'],
|
||||
'item-metadata-sections' => [],
|
||||
'item-metadata-section' => [],
|
||||
'item-metadata-sections' => ['render_callback' => 'tainacan_blocks_render_metadata_sections'],
|
||||
'item-metadata-section' => ['render_callback' => 'tainacan_blocks_render_metadata_section'],
|
||||
'item-metadata' => [],
|
||||
'item-metadatum' => ['render_callback' => 'tainacan_blocks_render_item_metadatum'],
|
||||
'metadata-section-name' => [],
|
||||
|
|
Loading…
Reference in New Issue