From b62f3f30b31d93bd321ca08ad03729400befbd71 Mon Sep 17 00:00:00 2001 From: Kuba Mikita Date: Wed, 12 Feb 2020 12:23:05 +0100 Subject: [PATCH 01/13] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3cf3e87..181a3e9 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ [![Total Downloads](https://poser.pugx.org/micropackage/acf-block-creator/downloads)](https://packagist.org/packages/micropackage/acf-block-creator) [![License](https://poser.pugx.org/micropackage/acf-block-creator/license)](https://packagist.org/packages/micropackage/acf-block-creator) +

+ Micropackage logo +

+ ## 🧬 About ACF Block Creator This package simplifies block creation for Gutengberg editor in WordPress using Advanced Custom Fields plugin. From b9205cc2748e7907a3c0d19bc1689e8f1f5e92e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20Sza=C5=82kiewicz?= Date: Wed, 15 Jul 2020 16:00:01 +0200 Subject: [PATCH 02/13] add stylelint-disable comment to generated scss file --- CHANGELOG.md | 4 ++++ src/ACFBlockCreator.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a7649f..00168b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [next] - [date] + +[Added] stylelint-disable comment in scss file + ## [1.0.0] - 27.01.2020 Initial release diff --git a/src/ACFBlockCreator.php b/src/ACFBlockCreator.php index b59ae39..93d3b25 100644 --- a/src/ACFBlockCreator.php +++ b/src/ACFBlockCreator.php @@ -236,7 +236,7 @@ public function update_field_group( $field_group ) { // Create block scss partial. if ( is_string( $this->config['scss_dir'] ) ) { - $scss = ".block.$slug {\n\n}"; + $scss = ".block.$slug {\n/* stylelint-disable */\n}"; if ( $this->maybe_mkdir( $this->config['scss_dir'] ) ) { $this->theme_fs->put_contents( "{$this->config['scss_dir']}/_{$slug}.scss", $scss ); From f52d4645a981a393e848ced3805a834db5100c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20Sza=C5=82kiewicz?= Date: Wed, 15 Jul 2020 16:01:58 +0200 Subject: [PATCH 03/13] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00168b2..2b82919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -## [next] - [date] +## [1.0.1] - 15.07.2020 [Added] stylelint-disable comment in scss file From 5cda428b3769c73124c0bd722c38ea5e9ba962be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20Sza=C5=82kiewicz?= Date: Wed, 15 Jul 2020 16:02:12 +0200 Subject: [PATCH 04/13] bump version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4c70dc6..65ab614 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "micropackage/acf-block-creator", - "version": "1.0.0", + "version": "1.0.1", "description": "ACF Block Creator - automatic block creation add-on for ACF", "license": "GPL-3.0-or-later", "authors": [ From 7653095dc1fb8a32a3fad391dd0eb73eec41eaae Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Wed, 29 Jul 2020 07:36:57 +0200 Subject: [PATCH 05/13] add inner blocks tag --- src/ACFBlockCreator.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ACFBlockCreator.php b/src/ACFBlockCreator.php index 93d3b25..f7aface 100644 --- a/src/ACFBlockCreator.php +++ b/src/ACFBlockCreator.php @@ -141,6 +141,17 @@ public function render_field_group_settings( $field_group ) { 'prefix' => 'acf_field_group', 'value' => isset( $field_group['block_container_class'] ) ? $field_group['block_container_class'] : $container_class, ] ); + + acf_render_field_wrap( [ + 'label' => 'Use Inner Blocks', + 'instructions' => 'Will add InnerBlocks element to the template', + 'type' => 'true_false', + 'name' => 'inner_blocks', + 'prefix' => 'acf_field_group', + 'value' => false, + 'ui' => true, + ] ); + } /** @@ -215,6 +226,11 @@ public function update_field_group( $field_group ) { $fields_markup[] = $this->get_field_markup( $field ); } + // Add inner blocks tag. + if ( $field_group['inner_blocks'] ) { + $fields_markup[] = ''; + } + $class = $field_group['block_container_class'] ? " class=\"{$field_group['block_container_class']}\"" : null; $template = $this->package_fs->get_contents( 'block.php' ); From 236e7886d1dcf89e758e10de4775d519b573116b Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Wed, 29 Jul 2020 07:39:14 +0200 Subject: [PATCH 06/13] add changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b82919..7cb1515 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## [Next] - [Date] + +* [Added] InnerBlocks support. + ## [1.0.1] - 15.07.2020 -[Added] stylelint-disable comment in scss file +* [Added] stylelint-disable comment in scss file. ## [1.0.0] - 27.01.2020 From a918fbf62fd1bb659bbbb9b877778c946b81ee59 Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Wed, 29 Jul 2020 07:40:25 +0200 Subject: [PATCH 07/13] change changelog format --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cb1515..557d1a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,14 @@ # Changelog All notable changes to this project will be documented in this file. -## [Next] - [Date] +## 1.0.2 * [Added] InnerBlocks support. -## [1.0.1] - 15.07.2020 +## 1.0.1 * [Added] stylelint-disable comment in scss file. -## [1.0.0] - 27.01.2020 +## 1.0.0 Initial release From 7d161791e15e016e93203ec0dfe576f9fceed66b Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Wed, 29 Jul 2020 07:40:41 +0200 Subject: [PATCH 08/13] change version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 65ab614..58d896b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "micropackage/acf-block-creator", - "version": "1.0.1", + "version": "1.0.2", "description": "ACF Block Creator - automatic block creation add-on for ACF", "license": "GPL-3.0-or-later", "authors": [ From b5b6002de249c0f3387d6a2259244c579677e899 Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Mon, 7 Sep 2020 20:07:45 +0200 Subject: [PATCH 09/13] fix jquery compatibility CU-7yr6q2 --- CHANGELOG.md | 4 ++++ assets/js/acf-block-creator.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557d1a6..1db8f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [Next] + +* [Fixed] jQuery compatibility in WordPress 5.5. + ## 1.0.2 * [Added] InnerBlocks support. diff --git a/assets/js/acf-block-creator.js b/assets/js/acf-block-creator.js index 052d721..ca1f3aa 100644 --- a/assets/js/acf-block-creator.js +++ b/assets/js/acf-block-creator.js @@ -1,6 +1,6 @@ ( function( $ ) { - var $block_option_fields = $( '#acf-field-group-options .acf-fields' ).find( '[data-name="block_name"], [data-name="block_slug"], [data-name="block_category"], [data-name="block_align"], [data-name="block_container_class"]' ); + var $block_option_fields = $( '#acf-field-group-options .acf-fields' ).find( '[data-name="block_name"], [data-name="block_slug"], [data-name="block_category"], [data-name="block_align"], [data-name="block_container_class"], [data-name="inner_blocks"]' ); $block_option_fields.hide(); @@ -14,8 +14,8 @@ } } ); - $( '#acf_field_group-create_gutenberg_block' ).click( function() { - if ( $( this ).attr( 'checked' ) ) { + $( '#acf_field_group-create_gutenberg_block' ).change( function() { + if ( $( this ).is( ':checked' ) ) { $block_option_fields.show(); } else { $block_option_fields.hide(); From 21bd7645adc1b2f9cc13b455d5b02344e3c4cad4 Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Mon, 7 Sep 2020 20:42:56 +0200 Subject: [PATCH 10/13] add acf 5.9 compatibility CU-7yr6q2 --- CHANGELOG.md | 1 + src/ACFBlockCreator.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1db8f77..c2bc070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## [Next] * [Fixed] jQuery compatibility in WordPress 5.5. +* [Fixed] ACF 5.9 compatibility. ## 1.0.2 diff --git a/src/ACFBlockCreator.php b/src/ACFBlockCreator.php index f7aface..821c84a 100644 --- a/src/ACFBlockCreator.php +++ b/src/ACFBlockCreator.php @@ -149,7 +149,7 @@ public function render_field_group_settings( $field_group ) { 'name' => 'inner_blocks', 'prefix' => 'acf_field_group', 'value' => false, - 'ui' => true, + 'ui' => false, ] ); } @@ -157,7 +157,7 @@ public function render_field_group_settings( $field_group ) { /** * Initiates Block Loader * - * @action acf/update_field_group 5 + * @action acf/update_field_group 15 * * @since 1.0.0 * @param array $field_group Field group params. From d43d8faf444438f8e949183a4f02b222bcfc8188 Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Mon, 7 Sep 2020 21:24:22 +0200 Subject: [PATCH 11/13] fixed block creation errors for layout fields CU-26cvdd --- CHANGELOG.md | 2 ++ src/ACFBlockCreator.php | 22 +++++++++++++++++----- src/block.php | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2bc070..d9a9672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. * [Fixed] jQuery compatibility in WordPress 5.5. * [Fixed] ACF 5.9 compatibility. +* [Fixed] Block creation when using layout fields like Message or Tabs. +* [Changed] Block template. ## 1.0.2 diff --git a/src/ACFBlockCreator.php b/src/ACFBlockCreator.php index 821c84a..b3a7f2e 100644 --- a/src/ACFBlockCreator.php +++ b/src/ACFBlockCreator.php @@ -34,6 +34,13 @@ public static function init( $config = [] ) { */ private $config; + /** + * Field types excluded from markup generation + * + * @var array + */ + private $excluded_field_types = [ 'message', 'accordion', 'tab' ]; + /** * Constructor * @@ -226,29 +233,30 @@ public function update_field_group( $field_group ) { $fields_markup[] = $this->get_field_markup( $field ); } + // Remove empty markup. + $fields_markup = array_filter( $fields_markup ); + // Add inner blocks tag. if ( $field_group['inner_blocks'] ) { $fields_markup[] = ''; } - $class = $field_group['block_container_class'] ? " class=\"{$field_group['block_container_class']}\"" : null; - $template = $this->package_fs->get_contents( 'block.php' ); $template = str_replace( [ '{COMMENT}', '{FIELDS}', - '{CLASS}', + '{CSS_CLASS}', ], [ substr( implode( "\n", $comment ), 3 ), implode( "\n", $fields_markup ), - $class, + $field_group['block_container_class'], ], $template ); - $this->theme_fs->put_contents( "{$this->config['blocks_dir']}/{$slug}.php", $template ); + $this->theme_fs->put_contents( "{$this->config['blocks_dir']}/{$slug}.php", rtrim( $template ) ); // Create block scss partial. if ( is_string( $this->config['scss_dir'] ) ) { @@ -330,6 +338,10 @@ private function maybe_mkdir( $dir ) { * @return string */ private function get_field_markup( $field ) { + if ( in_array( $field['type'], $this->excluded_field_types, true ) ) { + return ''; + } + $markup_file = "fields/{$field['type']}.php"; $markup_file = $this->package_fs->exists( $markup_file ) ? $markup_file : 'fields/default.php'; $markup = $this->package_fs->get_contents( $markup_file ); diff --git a/src/block.php b/src/block.php index a6f3ba3..b74f67f 100644 --- a/src/block.php +++ b/src/block.php @@ -7,7 +7,7 @@ ?> - +
{FIELDS} From f26f6c593f1826187f8716ec6c6bb13392b36e5c Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Mon, 7 Sep 2020 21:51:53 +0200 Subject: [PATCH 12/13] add support for line indentation CU-72treb --- CHANGELOG.md | 1 + src/ACFBlockCreator.php | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a9672..86843c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. * [Fixed] ACF 5.9 compatibility. * [Fixed] Block creation when using layout fields like Message or Tabs. * [Changed] Block template. +* [Added] Support for line indentation. ## 1.0.2 diff --git a/src/ACFBlockCreator.php b/src/ACFBlockCreator.php index b3a7f2e..c220201 100644 --- a/src/ACFBlockCreator.php +++ b/src/ACFBlockCreator.php @@ -41,6 +41,20 @@ public static function init( $config = [] ) { */ private $excluded_field_types = [ 'message', 'accordion', 'tab' ]; + /** + * Indentation character + * + * @var string + */ + private $indentation_char = "\t"; + + /** + * Indentation count + * + * @var int + */ + private $indentation = 1; + /** * Constructor * @@ -256,7 +270,7 @@ public function update_field_group( $field_group ) { $template ); - $this->theme_fs->put_contents( "{$this->config['blocks_dir']}/{$slug}.php", rtrim( $template ) ); + $this->theme_fs->put_contents( "{$this->config['blocks_dir']}/{$slug}.php", preg_replace( '/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', "\n\n", $template ) ); // Create block scss partial. if ( is_string( $this->config['scss_dir'] ) ) { @@ -348,6 +362,8 @@ private function get_field_markup( $field ) { $subfields = []; if ( 'repeater' === $field['type'] ) { + $this->indentation++; + foreach ( $field['sub_fields'] as $sub_field ) { $subfields[] = str_replace( [ @@ -361,20 +377,34 @@ private function get_field_markup( $field ) { $this->get_field_markup( $sub_field ) ); } + + $this->indentation--; } $markup = str_replace( [ '{name}', '{subfields}', + "\n", ], [ $field['name'], implode( "\n", $subfields ), + "\n" . $this->indentation(), ], $markup ); - return $markup; + return $this->indentation() . $markup; + } + + /** + * Gets current indentation + * + * @since 1.0.3 + * @return string + */ + private function indentation() { + return str_repeat( $this->indentation_char, $this->indentation ); } } From 1b7fc5dcb3412b1dc2da7910ba9b82f1cb506077 Mon Sep 17 00:00:00 2001 From: Jakub Mikita Date: Mon, 7 Sep 2020 21:54:55 +0200 Subject: [PATCH 13/13] bump version --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86843c9..0c381d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -## [Next] +## 1.0.3 * [Fixed] jQuery compatibility in WordPress 5.5. * [Fixed] ACF 5.9 compatibility. diff --git a/composer.json b/composer.json index 58d896b..08d3bf5 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "micropackage/acf-block-creator", - "version": "1.0.2", + "version": "1.0.3", "description": "ACF Block Creator - automatic block creation add-on for ACF", "license": "GPL-3.0-or-later", "authors": [