From bcc91d8c8b55833c92319d9eb14d5132500ad088 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 13 Aug 2024 01:02:48 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Simplify=20the=20localized=20block?= =?UTF-8?q?=20stub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/stubs/block.construct.stub | 108 --------------- src/Console/stubs/block.localized.stub | 184 +++++++++++++++++++++++++ 2 files changed, 184 insertions(+), 108 deletions(-) delete mode 100644 src/Console/stubs/block.construct.stub create mode 100644 src/Console/stubs/block.localized.stub diff --git a/src/Console/stubs/block.construct.stub b/src/Console/stubs/block.construct.stub deleted file mode 100644 index 1a22fd6..0000000 --- a/src/Console/stubs/block.construct.stub +++ /dev/null @@ -1,108 +0,0 @@ - __('DummyTitle', 'sage'), - 'description' => __('A simple DummyTitle block.', 'sage'), - 'category' => 'formatting', - 'icon' => 'editor-ul', - 'keywords' => [], - 'post_types' => [], - 'parent' => [], - 'ancestor' => [], - 'mode' => 'preview', - 'align' => '', - 'align_text' => '', - 'align_content' => '', - 'supports' => [ - 'align' => true, - 'align_text' => false, - 'align_content' => false, - 'full_height' => false, - 'anchor' => false, - 'mode' => false, - 'multiple' => true, - 'jsx' => true, - 'color' => [ - 'background' => true, - 'text' => true, - 'gradient' => true, - ], - ], - 'styles' => ['light', 'dark'], - 'template' => [ - 'core/heading' => ['placeholder' => 'Hello World'], - 'core/paragraph' => ['placeholder' => 'Welcome to the DummyTitle block.'], - ], - ]; - } - - /** - * The example data. - */ - public function example(): array - { - return [ - 'items' => [ - ['item' => 'Item one'], - ['item' => 'Item two'], - ['item' => 'Item three'], - ], - ]; - } - - /** - * Data to be passed to the block before rendering. - */ - public function with(): array - { - return [ - 'items' => $this->items(), - ]; - } - - /** - * The block field group. - */ - public function fields(): array - { - $fields = Builder::make('DummySnake'); - - $fields - ->addRepeater('items') - ->addText('item') - ->endRepeater(); - - return $fields->build(); - } - - /** - * Return the items field. - * - * @return array - */ - public function items() - { - return get_field('items') ?: $this->example['items']; - } - - /** - * Assets enqueued when rendering the block. - */ - public function assets(array $block): void - { - // - } -} diff --git a/src/Console/stubs/block.localized.stub b/src/Console/stubs/block.localized.stub new file mode 100644 index 0000000..48ffb55 --- /dev/null +++ b/src/Console/stubs/block.localized.stub @@ -0,0 +1,184 @@ + [ + ['item' => 'Item one'], + ['item' => 'Item two'], + ['item' => 'Item three'], + ], + ]; + + /** + * The block template. + * + * @var array + */ + public $template = [ + 'core/heading' => ['placeholder' => 'Hello World'], + 'core/paragraph' => ['placeholder' => 'Welcome to the DummyTitle block.'], + ]; + + /** + * The block name. + */ + public function getName(): string + { + return __('DummyTitle', 'sage'); + } + + /** + * The block description. + */ + public function getDescription(): string + { + return __('DummyDescription', 'sage'); + } + + /** + * Data to be passed to the block before rendering. + */ + public function with(): array + { + return [ + 'items' => $this->items(), + ]; + } + + /** + * The block field group. + */ + public function fields(): array + { + $fields = Builder::make('DummySnake'); + + $fields + ->addRepeater('items') + ->addText('item') + ->endRepeater(); + + return $fields->build(); + } + + /** + * Retrieve the items. + * + * @return array + */ + public function items() + { + return get_field('items') ?: $this->example['items']; + } + + /** + * Assets enqueued when rendering the block. + */ + public function assets(array $block): void + { + // + } +}