Better check boolean values on the save function #674.

This commit is contained in:
mateuswetah 2022-03-04 11:26:57 -03:00
parent a7be880952
commit aa40c5fb87
2 changed files with 20 additions and 19 deletions

View File

@ -53,7 +53,7 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
label={__('Document', 'tainacan')} label={__('Document', 'tainacan')}
checked={ mediaSources['document'] === true } checked={ mediaSources['document'] === true }
onChange={ ( isChecked ) => { onChange={ ( isChecked ) => {
let updatedSources = JSON.parse(JSON.stringify(mediaSources)); let updatedSources = Object.assign({},mediaSources);
updatedSources['document'] = isChecked; updatedSources['document'] = isChecked;
setAttributes({ mediaSources: updatedSources }); setAttributes({ mediaSources: updatedSources });
} }
@ -63,7 +63,7 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
label={__('Attachments', 'tainacan')} label={__('Attachments', 'tainacan')}
checked={ mediaSources['attachments'] === true } checked={ mediaSources['attachments'] === true }
onChange={ ( isChecked ) => { onChange={ ( isChecked ) => {
let updatedSources = JSON.parse(JSON.stringify(mediaSources)); let updatedSources = Object.assign({},mediaSources);
updatedSources['attachments'] = isChecked; updatedSources['attachments'] = isChecked;
setAttributes({ mediaSources: updatedSources }); setAttributes({ mediaSources: updatedSources });
} }
@ -73,7 +73,7 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
label={__('Metadata', 'tainacan')} label={__('Metadata', 'tainacan')}
checked={ mediaSources['metadata'] === true } checked={ mediaSources['metadata'] === true }
onChange={ ( isChecked ) => { onChange={ ( isChecked ) => {
let updatedSources = JSON.parse(JSON.stringify(mediaSources)); let updatedSources = Object.assign({},mediaSources);
updatedSources['metadata'] = isChecked; updatedSources['metadata'] = isChecked;
setAttributes({ mediaSources: updatedSources }); setAttributes({ mediaSources: updatedSources });
} }
@ -88,7 +88,7 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
label={__('Main slider', 'tainacan')} label={__('Main slider', 'tainacan')}
checked={ layoutElements['main'] === true } checked={ layoutElements['main'] === true }
onChange={ ( isChecked ) => { onChange={ ( isChecked ) => {
let updatedElements = JSON.parse(JSON.stringify(layoutElements)); let updatedElements = Object.assign({},layoutElements);
updatedElements['main'] = isChecked; updatedElements['main'] = isChecked;
setAttributes({ layoutElements: updatedElements }); setAttributes({ layoutElements: updatedElements });
} }
@ -98,7 +98,8 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
label={__('Thumbnails carousel', 'tainacan')} label={__('Thumbnails carousel', 'tainacan')}
checked={ layoutElements['thumbnails'] === true } checked={ layoutElements['thumbnails'] === true }
onChange={ (isChecked) => { onChange={ (isChecked) => {
let updatedElements = JSON.parse(JSON.stringify(layoutElements)); console.log(typeof layoutElements['thumbnails'])
let updatedElements = Object.assign({},layoutElements);
updatedElements['thumbnails'] = isChecked; updatedElements['thumbnails'] = isChecked;
setAttributes({ layoutElements: updatedElements }); setAttributes({ layoutElements: updatedElements });
} }

View File

@ -30,10 +30,10 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
$media_items_main = array(); $media_items_main = array();
$media_items_thumbnails = array(); $media_items_thumbnails = array();
if ( isset($media_sources['attachments']) && $media_sources['attachments'] ) if ( isset($media_sources['attachments']) && ($media_sources['attachments'] === true || $media_sources['attachments'] == 'true') )
$attachments = tainacan_get_the_attachments(null, $item_id); $attachments = tainacan_get_the_attachments(null, $item_id);
if ( isset($layout_elements['main']) && $layout_elements['main'] ) { if ( isset($layout_elements['main']) && ($layout_elements['main'] === true || $layout_elements['main'] == 'true') ) {
$class_slide_metadata = ''; $class_slide_metadata = '';
if ($hide_file_name_main) if ($hide_file_name_main)
@ -43,7 +43,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
if ($hide_file_caption_main) if ($hide_file_caption_main)
$class_slide_metadata .= ' hide-caption'; $class_slide_metadata .= ' hide-caption';
if ( isset($media_sources['document']) && $media_sources['document'] && !empty(tainacan_get_the_document($item_id)) ) { if ( isset($media_sources['document']) && ($media_sources['document'] === true || $media_sources['document'] == 'true') && !empty(tainacan_get_the_document($item_id)) ) {
$is_document_type_attachment = tainacan_get_the_document_type($item_id) === 'attachment'; $is_document_type_attachment = tainacan_get_the_document_type($item_id) === 'attachment';
$media_items_main[] = $media_items_main[] =
tainacan_get_the_media_component_slide(array( tainacan_get_the_media_component_slide(array(
@ -60,7 +60,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
)); ));
} }
if ( isset($media_sources['attachments']) && $media_sources['attachments'] ) { if ( isset($media_sources['attachments']) && ($media_sources['attachments'] === true || $media_sources['attachments'] == 'true') ) {
foreach ( $attachments as $attachment ) { foreach ( $attachments as $attachment ) {
$media_items_main[] = $media_items_main[] =
tainacan_get_the_media_component_slide(array( tainacan_get_the_media_component_slide(array(
@ -79,7 +79,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
} }
} }
if ( isset($layout_elements['thumbnails']) && $layout_elements['thumbnails'] ) { if ( isset($layout_elements['thumbnails']) && ($layout_elements['thumbnails'] === true || $layout_elements['thumbnails'] == 'true') ) {
$class_slide_metadata = ''; $class_slide_metadata = '';
if ($hide_file_name_thumbnails) if ($hide_file_name_thumbnails)
@ -89,7 +89,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
if ($hide_file_caption_thumbnails) if ($hide_file_caption_thumbnails)
$class_slide_metadata .= ' hide-caption'; $class_slide_metadata .= ' hide-caption';
if ( isset($media_sources['document']) && $media_sources['document'] && !empty(tainacan_get_the_document($item_id)) ) { if ( isset($media_sources['document']) && ($media_sources['document'] === true && $media_sources['document'] == 'true') && !empty(tainacan_get_the_document($item_id)) ) {
$is_document_type_attachment = tainacan_get_the_document_type($item_id) === 'attachment'; $is_document_type_attachment = tainacan_get_the_document_type($item_id) === 'attachment';
$media_items_thumbnails[] = $media_items_thumbnails[] =
tainacan_get_the_media_component_slide(array( tainacan_get_the_media_component_slide(array(
@ -103,7 +103,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
)); ));
} }
if ( isset($media_sources['attachments']) && $media_sources['attachments'] ) { if ( isset($media_sources['attachments']) && ($media_sources['attachments'] === true || $media_sources['attachments'] == 'true') ) {
foreach ( $attachments as $attachment ) { foreach ( $attachments as $attachment ) {
$media_items_thumbnails[] = $media_items_thumbnails[] =
tainacan_get_the_media_component_slide(array( tainacan_get_the_media_component_slide(array(
@ -126,12 +126,12 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
$wrapper_attributes, $wrapper_attributes,
tainacan_get_the_media_component( tainacan_get_the_media_component(
'tainacan-item-gallery-block_id-' . $block_id, 'tainacan-item-gallery-block_id-' . $block_id,
(isset($layout_elements['thumbnails']) && $layout_elements['thumbnails']) ? $media_items_thumbnails : null, (isset($layout_elements['thumbnails']) && ($layout_elements['thumbnails'] === true || $layout_elements['thumbnails'] == 'true')) ? $media_items_thumbnails : null,
(isset($layout_elements['main']) && $layout_elements['main']) ? $media_items_main : null, (isset($layout_elements['main']) && ($layout_elements['main'] === true || $layout_elements['main'] == 'true')) ? $media_items_main : null,
array( array(
'class_main_div' => '', 'class_main_div' => '',
'class_thumbs_div' => '', 'class_thumbs_div' => '',
'swiper_main_options' => (isset($layout_elements['main']) && $layout_elements['main']) ? array( 'swiper_main_options' => (isset($layout_elements['main']) && ($layout_elements['main'] === true || $layout_elements['main'] == 'true')) ? array(
'navigation' => array( 'navigation' => array(
'nextEl' => '.swiper-navigation-next_' . 'tainacan-item-gallery-block_id-' . $block_id . '-main', 'nextEl' => '.swiper-navigation-next_' . 'tainacan-item-gallery-block_id-' . $block_id . '-main',
'prevEl' => '.swiper-navigation-prev_' . 'tainacan-item-gallery-block_id-' . $block_id . '-main', 'prevEl' => '.swiper-navigation-prev_' . 'tainacan-item-gallery-block_id-' . $block_id . '-main',
@ -139,7 +139,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) {
'lazy' => true 'lazy' => true
) )
) : '', ) : '',
'swiper_thumbs_options' => (isset($layout_elements['thumbnails']) && $layout_elements['thumbnails'] && (!isset($layout_elements['main']) || !$layout_elements['main']) ) ? array( 'swiper_thumbs_options' => (isset($layout_elements['thumbnails']) && ($layout_elements['thumbnails'] === true || $layout_elements['thumbnails'] == 'true') && (!isset($layout_elements['main']) || !($layout_elements['main'] === true || $layout_elements['main'] == 'true')) ) ? array(
'navigation' => array( 'navigation' => array(
'nextEl' => '.swiper-navigation-next_' . 'tainacan-item-gallery-block_id-' . $block_id . '-thumbs', 'nextEl' => '.swiper-navigation-next_' . 'tainacan-item-gallery-block_id-' . $block_id . '-thumbs',
'prevEl' => '.swiper-navigation-prev_' . 'tainacan-item-gallery-block_id-' . $block_id . '-thumbs', 'prevEl' => '.swiper-navigation-prev_' . 'tainacan-item-gallery-block_id-' . $block_id . '-thumbs',