Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FAQ]ブロック毎にアコーディオンの初期設定を追加しました #1750

Merged
merged 10 commits into from
Jul 7, 2023
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ e.g.

== Changelog ==

[ Add Function ][ FAQ2 ] Add an accordion default option on a per-block.
[ Specification Change ] Disable HTML editing for blocks with inner blocks, as the blocks are broken.
[ Bug fix ][ Dynamic Text (Pro) ] Fix php warning that brought by can't get post type name on search result page.
[ Bug fix ][ Dynamic Text (Pro) ] Fix php warning that brought by can't get ancestor page on search result page.
Expand Down
6 changes: 6 additions & 0 deletions src/admin/new-faq.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export default function AdminNewFaq() {
<h3 id="faq-setting">
{__('FAQ Block Setting', 'vk-blocks-pro')}
</h3>
<p>
{__(
'Please specify a common accordion setting to be used in the FAQ block.',
'vk-blocks-pro'
)}
</p>
<SelectControl
name="vk_blocks_options[new_faq_accordion]"
className="vk_admin_selectControl"
Expand Down
6 changes: 6 additions & 0 deletions src/blocks/faq2/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
"html": false,
"anchor": true,
"className": true
},
"attributes": {
"showContent": {
"type": "string",
"default": "default"
}
}
}
79 changes: 62 additions & 17 deletions src/blocks/faq2/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
InspectorControls,
useBlockProps,
} from '@wordpress/block-editor';
import { PanelBody, PanelRow } from '@wordpress/components';
import { BaseControl, PanelBody, SelectControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export default function FAQ2Edit() {
export default function FAQ2Edit(props) {
const { attributes, setAttributes } = props;
const { showContent } = attributes;
const blockProps = useBlockProps({
className: 'vk_faq',
});
Expand All @@ -15,25 +17,68 @@ export default function FAQ2Edit() {

const TEMPLATE = [['vk-blocks/faq2-q'], ['vk-blocks/faq2-a']];

let massage;
// eslint-disable-next-line no-undef
if (vk_blocks_check.is_pro) {
massage = __(
'If you want to be collapsing this block, you can set it at Setting > VK Blocks',
'vk-blocks-pro'
);
} else {
massage = __(
'You can be collapsing this block at VK Blocks Pro',
'vk-blocks-pro'
);
}

return (
<>
<InspectorControls>
<PanelBody title={__('Accordion Setting', 'vk-blocks-pro')}>
<PanelRow>{massage}</PanelRow>
{/* eslint-disable-next-line no-undef */}
{vk_blocks_check.is_pro ? (
<BaseControl>
<SelectControl
__nextHasNoMarginBottom
name="vk_blocks_options[new_faq_accordion]"
value={showContent}
onChange={(value) => {
setAttributes({
showContent: value,
});
}}
options={[
{
label: __(
'Use common settings',
'vk-blocks-pro'
),
value: 'default',
},
{
label: __(
'Disable accordion',
'vk-blocks-pro'
),
value: 'disable',
},
{
label: __(
'Enable accordion and default open',
'vk-blocks-pro'
),
value: 'open',
},
{
label: __(
'Enable accordion and default close',
'vk-blocks-pro'
),
value: 'close',
},
]}
/>
<p>
{__(
'* You can change each common accordion settings from Setting > VK Blocks.',
'vk-blocks-pro'
)}
</p>
</BaseControl>
) : (
<p>
{__(
'You can be collapsing this block at VK Blocks Pro',
'vk-blocks-pro'
)}
</p>
)}
</PanelBody>
</InspectorControls>
<div {...blockProps}>
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/faq2/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function vk_blocks_register_block_faq2() {
function vk_blocks_faq2_render_callback( $block_content, $block ) {
$vk_blocks_options = VK_Blocks_Options::get_options();
if ( 'vk-blocks/faq2' === $block['blockName'] ) {
if ( ! empty( $block['attrs']['showContent'] ) && 'default' !== $block['attrs']['showContent'] ) {
$vk_blocks_options['new_faq_accordion'] = $block['attrs']['showContent'];
}

if ( ! empty( $vk_blocks_options['new_faq_accordion'] ) && 'open' === $vk_blocks_options['new_faq_accordion'] ) {
$block_content = str_replace( '[accordion_trigger_switch]', 'vk_faq-accordion vk_faq-accordion-open', $block_content );
} elseif ( ! empty( $vk_blocks_options['new_faq_accordion'] ) && 'close' === $vk_blocks_options['new_faq_accordion'] ) {
Expand Down