Skip to content

Commit 6658737

Browse files
authored
Merge pull request #317 from moderntribe/task/MOOSE-344/update-create-block-script
[MOOSE-344] FE: Update `create-block` Script Template Files
2 parents 46f4aa0 + 7e9e488 commit 6658737

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ item (Added, Changed, Depreciated, Removed, Fixed, Security).
1111
- Updated: Expected PHP version to v8.4, Node version to v24 LTS
1212
- Updated: WordPress to v6.9.1
1313
- Updated: All plugins, composer dependencies, and npm packages to latest versions.
14+
- Updated: `npm run create-block` script template files updated.
1415
- Added: New Accordion block styling
1516
- Removed: Details block styling
1617
- Fixed: pre-push git hooks running properly again.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{#isDynamicVariant}}
2+
<?php declare(strict_types=1);
3+
4+
namespace Tribe\Plugin\Components\Blocks;
5+
6+
use Tribe\Plugin\Components\Abstracts\Abstract_Block_Controller;
7+
8+
/**
9+
* TODO:
10+
* - Rename class & file name to match the block name.
11+
* - Move file to wp-content/plugins/core/src/Components/Blocks/
12+
* - If this is a card block, update the Abstract_Block_Controller class to Abstract_Card_Controller.
13+
* - If this block contains post data:
14+
* - Use `use Tribe\Plugin\Components\Traits\Post_Data;`.
15+
* - Add `use Post_Data;` within this class to inherit the post data trait + methods.
16+
* - Extend / update to include any block specific logic & fields
17+
*/
18+
19+
class Block_Controller extends Abstract_Block_Controller {
20+
21+
protected string $example_text_control;
22+
23+
public function __construct( array $args = [] ) {
24+
parent::__construct( $args );
25+
26+
$this->example_text_control = $this->attributes['exampleTextControl'] ?? '';
27+
}
28+
29+
public function get_example_text_control(): string {
30+
return $this->example_text_control;
31+
}
32+
33+
}
34+
{{/isDynamicVariant}}

dev/templates/block/edit.js.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export default function Edit( { attributes, setAttributes, isSelected } ) {
1515
return (
1616
<div { ...blockProps }>
1717
{{#isDynamicVariant}}
18-
<ServerSideRender block="{{namespace}}/{{slug}}" attributes={ attributes } />
18+
<ServerSideRender
19+
block="tribe/test-dynamic"
20+
attributes={ attributes }
21+
/>
1922
{{/isDynamicVariant}}
2023
{{#isStaticVariant}}
2124
<p>{ __( '{{title}} – hello from the editor!', '{{namespace}}' ) }</p>

dev/templates/block/editor.pcss.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
*
55
* ------------------------------------------------------------------------- */
66

7-
{{#isDynamicVariant}}section{{/isDynamicVariant}}.wp-block-{{namespace}}-{{slug}} {
7+
{{#isDynamicVariant}}.b-{{slug}}{{/isDynamicVariant}}{{#isStaticVariant}}.wp-block-{{namespace}}-{{slug}}{{/isStaticVariant}} {
88
border: 1px dotted #f00;
99
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
{{#isDynamicVariant}}
22
<?php declare(strict_types=1);
33

4-
$example_text_control = $attributes['exampleTextControl']; // @phpstan-ignore-line
4+
/**
5+
* @var array $attributes
6+
*/
7+
8+
$c = Block_Controller::factory( [
9+
'attributes' => $attributes,
10+
'block_classes' => 'b-{{slug}}',
11+
] );
512
?>
6-
<section <?php echo get_block_wrapper_attributes(); ?>>
13+
<section <?php echo get_block_wrapper_attributes( [ 'class' => esc_attr( $c->get_block_classes() ), 'style' => $c->get_block_styles() ] ); ?>>
714
<p><?php esc_html_e( '{{title}} – hello from a dynamic block!', '{{namespace}}' ); ?></p>
8-
<?php if ( $example_text_control ) : ?>
9-
<p><?php echo esc_html( $example_text_control ); ?></p>
10-
<?php endif; ?>
15+
<p><?php echo esc_html( $c->get_example_text_control() ); ?></p>
1116
</section>
1217
{{/isDynamicVariant}}

dev/templates/block/style.pcss.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* ------------------------------------------------------------------------- */
66

7-
.wp-block-{{namespace}}-{{slug}} {
7+
{{#isDynamicVariant}}.b-{{slug}}{{/isDynamicVariant}}{{#isStaticVariant}}.wp-block-{{namespace}}-{{slug}}{{/isStaticVariant}} {
88
background-color: #21759b;
99
color: #fff;
1010
padding: 2px;

0 commit comments

Comments
 (0)