Skip to content

Commit

Permalink
📦 NEW: v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
colorful-tones committed Oct 6, 2022
0 parents commit f4d0ee8
Show file tree
Hide file tree
Showing 14 changed files with 12,106 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Node / npm
node_modules

# System - macOS
.DS_Store
74 changes: 74 additions & 0 deletions acf-accordion-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Plugin Name: ACF Accordion Block
* Description: An accordion block with ACF fields.
* Requires at least: 6.0
* Requires PHP: 7.0
* Version: 1.0.0
* Author: Damon Cook
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: acf-accordion-block
*
* @package acf-accordion-block
*/

/**
* We register the block on init, earlier than acf/init,
* so we can make sure we ask ACF to load this block's fields.
*
* @return void
*/
function acf_accordion_block_register() {
register_block_type( dirname(__FILE__) . '/build/block.json' );
}
add_action( 'init', 'acf_accordion_block_register', 5 );

/**
* Register our block's fields into ACF.
*
* @return void
*/
function acf_accordion_block_register_include_fields() {
$path = __DIR__ . '/acf-fields.json';
$field_json = json_decode( file_get_contents( $path ), true );
$field_json['location'] = array(
array(
array(
'param' => 'block',
'operator' => '==',
'value' => 'acf/accordion', // block.json name.
),
),
);
$field_json['local'] = 'json';
$field_json['local_file'] = $path;

acf_add_local_field_group( $field_json );
}
add_action( 'acf/include_fields', 'acf_accordion_block_register_include_fields' );

/**
* Register a custom block category for our blocks.
*
* @link https://developer.wordpress.org/reference/hooks/block_categories_all/
*
* @param array $block_categories Existing block categories
* @return array Block categories
*/
function acf_accordion_block_block_categories( $block_categories ) {

$block_categories = array_merge(
[
[
'slug' => 'acf-blocks',
'title' => __( 'ACF Blocks', 'acf_accordion_block' ),
'icon' => '<svg viewBox="0 0 55 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M43.9986 23.8816H38.0521V0.0253448H53.9034V5.58064H43.9986V9.83762H53.334V15.2547H43.9986V23.8825V23.8816Z" fill="black"/><path opacity="0.05" d="M36.4832 13.8697H42.3772C41.5051 19.9417 36.3849 23.9574 30.1814 23.9574C23.3882 23.9574 17.8572 18.8809 17.8572 12.0448C17.843 10.4551 18.1521 8.879 18.7658 7.41239C19.3795 5.94579 20.2849 4.61924 21.4271 3.51334C23.7714 1.24304 26.9182 -0.00834104 30.1814 0.0320335C36.3275 0.0320335 41.5908 4.07879 42.3392 10.0536H36.4511C34.6807 3.2856 23.649 3.94741 23.649 12.0448C23.649 20.1432 34.8189 20.7398 36.4832 13.8716V13.8697Z" fill="black"/><path d="M35.2772 13.8697C34.266 17.2858 30.667 19.317 27.1244 18.4664C23.5798 17.6128 21.3588 14.187 22.0946 10.7047C22.8294 7.22146 26.2572 4.92655 29.8582 5.50758C31.3334 5.70738 32.6937 6.41247 33.7074 7.50273C34.408 8.22394 34.9337 9.0963 35.2442 10.0526H40.96C40.2116 4.06425 34.9337 0.0320875 28.8022 0.0320875C25.5386 -0.00942939 22.391 1.24129 20.0459 3.51144C18.903 4.61761 17.997 5.94473 17.3831 7.41208C16.7693 8.87942 16.4603 10.4563 16.4751 12.0468C16.4751 18.8829 21.9739 23.9574 28.8042 23.9574C35.0028 23.9574 40.1084 19.9418 40.996 13.8697H35.2763H35.2772Z" fill="black"/><path opacity="0.05" d="M17.5146 20.4109H9.2391L7.88629 23.8776H1.55337L11.245 0H15.4689L25.5459 23.8854H18.8597L17.5127 20.4109H17.5146ZM11.5914 14.5004L11.3841 15.0396H15.4017L15.2625 14.6347L13.3919 9.51446L11.5914 14.5004Z" fill="black"/><path d="M15.9476 20.4109H7.68573L6.33389 23.8776H0L9.69257 0H13.9165L23.9935 23.8854H17.3102L15.9476 20.4109ZM10.0381 14.5004L9.83174 15.0396H13.8493L13.7092 14.6347L11.8396 9.51446L10.039 14.5004H10.0381Z" fill="black"/></svg>',
]
],
$block_categories,
);

return $block_categories;
}
add_filter( 'block_categories_all', 'acf_accordion_block_block_categories' );
69 changes: 69 additions & 0 deletions acf-fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"key": "group_accordion_block",
"title": "Block: Accordion",
"fields": [
{
"key": "field_632ddf04b0ad6",
"label": "Accordion Item",
"name": "accordion_item",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "row",
"pagination": 0,
"min": 0,
"max": 0,
"collapsed": "field_632ddf29b0ad7",
"button_label": "Add Accordion Item",
"rows_per_page": 20,
"sub_fields": [
{
"key": "field_632ddf29b0ad7",
"label": "Accordion heading",
"name": "accordion_heading",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": "",
"parent_repeater": "field_632ddf04b0ad6"
},
{
"key": "field_632ddf37b0ad8",
"label": "Accordion content",
"name": "accordion_content",
"type": "wysiwyg",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"delay": 1,
"tabs": "all",
"toolbar": "full",
"media_upload": 1,
"parent_repeater": "field_632ddf04b0ad6"
}
]
}
]
}
1 change: 1 addition & 0 deletions build/accordion.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '73f1137cf6272df332f9');
1 change: 1 addition & 0 deletions build/accordion.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/accordion.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions build/accordion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Accordion block.
*/

/**
* This index is key to keeping things accessible,
* and having unique Aria assignments.
*/
$i = 0;
$wrapper_attributes = get_block_wrapper_attributes(
[
'class' => 'accordion'
]
);
?>

<div <?php echo $wrapper_attributes; ?>>
<?php foreach ( get_field( 'accordion_item' ) as $accordion_item ) : ?>
<h3 class="accordion-heading">
<button type="button"
aria-expanded="<?php echo ( $i === 0 ) ? 'true' : 'false'; ?>"
class="accordion-trigger"
aria-controls="accordion-section-<?php echo $i; ?>"
id="accordion-<?php echo $i; ?>">
<span class="accordion-title">
<?php echo $accordion_item['accordion_heading']; ?>
<span class="accordion-icon"></span>
</span>
</button>
</h3><!-- .accordion-heading -->

<div id="accordion-section-<?php echo $i; ?>"
role="region"
aria-labelledby="accordion-<?php echo $i; ?>"
class="accordion-panel"
<?php echo ( $i !== 0 ) ? 'hidden' : ''; ?>>
<div class="accordion-content">
<?php echo $accordion_item['accordion_content']; ?>
</div><!-- .accordion-content -->
</div><!-- .accordion-section-<?php echo $i; ?> -->

<?php
$i++;
endforeach;
?>
</div><!-- .accordion -->
25 changes: 25 additions & 0 deletions build/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "acf/accordion",
"title": "Accordion",
"description": "An accordion block with collapsible sections.",
"style": "file:./accordion.css",
"script": "file:./accordion.js",
"category": "acf-blocks",
"icon": "menu-alt3",
"supports": {
"color": {
"text": true,
"background": false
}
},
"keywords": [
"accordion",
"toggle",
"expand"
],
"acf": {
"mode": "preview",
"renderTemplate": "accordion.php",
"blockVersion": 2
}
}

0 comments on commit f4d0ee8

Please sign in to comment.