diff --git a/composer.lock b/composer.lock index 4fc275f4c..9499007ae 100644 --- a/composer.lock +++ b/composer.lock @@ -70,16 +70,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.227.0", + "version": "3.228.3", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "88d803113ade68604ec03c591d65e1e44406ab8e" + "reference": "4dad57c95c7ff1dfcea29a7877ce64720b3318c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/88d803113ade68604ec03c591d65e1e44406ab8e", - "reference": "88d803113ade68604ec03c591d65e1e44406ab8e", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4dad57c95c7ff1dfcea29a7877ce64720b3318c3", + "reference": "4dad57c95c7ff1dfcea29a7877ce64720b3318c3", "shasum": "" }, "require": { @@ -87,7 +87,7 @@ "ext-json": "*", "ext-pcre": "*", "ext-simplexml": "*", - "guzzlehttp/guzzle": "^6.5.7 || ^7.4.4", + "guzzlehttp/guzzle": "^6.5.8 || ^7.4.5", "guzzlehttp/promises": "^1.4.0", "guzzlehttp/psr7": "^1.8.5 || ^2.3", "mtdowling/jmespath.php": "^2.6", @@ -155,9 +155,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.227.0" + "source": "https://github.com/aws/aws-sdk-php/tree/3.228.3" }, - "time": "2022-06-17T18:15:06+00:00" + "time": "2022-06-24T20:24:09+00:00" }, { "name": "clue/stream-filter", @@ -635,22 +635,22 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.4.4", + "version": "7.4.5", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8" + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8", - "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.5", - "guzzlehttp/psr7": "^1.8.3 || ^2.1", + "guzzlehttp/psr7": "^1.9 || ^2.4", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", "symfony/deprecation-contracts": "^2.2 || ^3.0" @@ -739,7 +739,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.4.4" + "source": "https://github.com/guzzle/guzzle/tree/7.4.5" }, "funding": [ { @@ -755,7 +755,7 @@ "type": "tidelift" } ], - "time": "2022-06-09T21:39:15+00:00" + "time": "2022-06-20T22:16:13+00:00" }, { "name": "guzzlehttp/promises", @@ -843,16 +843,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.8.5", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "337e3ad8e5716c15f9657bd214d16cc5e69df268" + "reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/337e3ad8e5716c15f9657bd214d16cc5e69df268", - "reference": "337e3ad8e5716c15f9657bd214d16cc5e69df268", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/e98e3e6d4f86621a9b75f623996e6bbdeb4b9318", + "reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318", "shasum": "" }, "require": { @@ -873,7 +873,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -933,7 +933,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.8.5" + "source": "https://github.com/guzzle/psr7/tree/1.9.0" }, "funding": [ { @@ -949,7 +949,7 @@ "type": "tidelift" } ], - "time": "2022-03-20T21:51:18+00:00" + "time": "2022-06-20T21:43:03+00:00" }, { "name": "humanmade/s3-uploads", @@ -1384,16 +1384,16 @@ }, { "name": "moderntribe/square1-field-models", - "version": "1.1.2", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/moderntribe/square1-field-models.git", - "reference": "449275a3fd206555fcc6524343234ba24d314651" + "reference": "7635662e41909fbd57800a1259b4cd11922efbfe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/moderntribe/square1-field-models/zipball/449275a3fd206555fcc6524343234ba24d314651", - "reference": "449275a3fd206555fcc6524343234ba24d314651", + "url": "https://api.github.com/repos/moderntribe/square1-field-models/zipball/7635662e41909fbd57800a1259b4cd11922efbfe", + "reference": "7635662e41909fbd57800a1259b4cd11922efbfe", "shasum": "" }, "require": { @@ -1419,9 +1419,9 @@ "description": "Data Transfer Objects (models) for Advanced custom fields", "support": { "issues": "https://github.com/moderntribe/square1-field-models/issues", - "source": "https://github.com/moderntribe/square1-field-models/tree/1.1.2" + "source": "https://github.com/moderntribe/square1-field-models/tree/1.1.4" }, - "time": "2022-05-11T17:12:21+00:00" + "time": "2022-06-25T05:00:10+00:00" }, { "name": "moderntribe/tribe-acf-post-list-field", @@ -4117,16 +4117,16 @@ }, { "name": "codeception/codeception", - "version": "4.2.0", + "version": "4.2.1", "source": { "type": "git", "url": "https://github.com/Codeception/Codeception.git", - "reference": "e646d160bf1223d3595b227b69d903777fbcfb5f" + "reference": "77b3e2003fd4446b35826cb9dc397129c521c888" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeception/Codeception/zipball/e646d160bf1223d3595b227b69d903777fbcfb5f", - "reference": "e646d160bf1223d3595b227b69d903777fbcfb5f", + "url": "https://api.github.com/repos/Codeception/Codeception/zipball/77b3e2003fd4446b35826cb9dc397129c521c888", + "reference": "77b3e2003fd4446b35826cb9dc397129c521c888", "shasum": "" }, "require": { @@ -4203,7 +4203,7 @@ ], "support": { "issues": "https://github.com/Codeception/Codeception/issues", - "source": "https://github.com/Codeception/Codeception/tree/4.2.0" + "source": "https://github.com/Codeception/Codeception/tree/4.2.1" }, "funding": [ { @@ -4211,7 +4211,7 @@ "type": "open_collective" } ], - "time": "2022-06-16T05:33:39+00:00" + "time": "2022-06-22T06:18:59+00:00" }, { "name": "codeception/lib-asserts", @@ -5155,16 +5155,16 @@ }, { "name": "illuminate/collections", - "version": "v8.83.16", + "version": "v8.83.17", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "fc232e89c0214dba5d2b431220a24b02d480a472" + "reference": "71cc806cf214a287dd4a86cac09171a84c3aa573" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/fc232e89c0214dba5d2b431220a24b02d480a472", - "reference": "fc232e89c0214dba5d2b431220a24b02d480a472", + "url": "https://api.github.com/repos/illuminate/collections/zipball/71cc806cf214a287dd4a86cac09171a84c3aa573", + "reference": "71cc806cf214a287dd4a86cac09171a84c3aa573", "shasum": "" }, "require": { @@ -5205,11 +5205,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-03-25T14:53:23+00:00" + "time": "2022-06-17T02:35:16+00:00" }, { "name": "illuminate/contracts", - "version": "v8.83.16", + "version": "v8.83.17", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -5257,7 +5257,7 @@ }, { "name": "illuminate/macroable", - "version": "v8.83.16", + "version": "v8.83.17", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -5303,7 +5303,7 @@ }, { "name": "illuminate/support", - "version": "v8.83.16", + "version": "v8.83.17", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", @@ -6265,16 +6265,16 @@ }, { "name": "php-stubs/wordpress-stubs", - "version": "v5.9.3", + "version": "v6.0.0", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "18d56875e5078a50b8ea4bc4b20b735ca61edeee" + "reference": "ce909ee303ce4bb885e5009a739c19b461944166" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/18d56875e5078a50b8ea4bc4b20b735ca61edeee", - "reference": "18d56875e5078a50b8ea4bc4b20b735ca61edeee", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/ce909ee303ce4bb885e5009a739c19b461944166", + "reference": "ce909ee303ce4bb885e5009a739c19b461944166", "shasum": "" }, "replace": { @@ -6306,9 +6306,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v5.9.3" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.0.0" }, - "time": "2022-04-06T15:33:59+00:00" + "time": "2022-05-26T14:35:42+00:00" }, { "name": "php-stubs/wordpress-tests-stubs", @@ -10005,21 +10005,21 @@ }, { "name": "szepeviktor/phpstan-wordpress", - "version": "v1.1.1", + "version": "v1.1.2", "source": { "type": "git", "url": "https://github.com/szepeviktor/phpstan-wordpress.git", - "reference": "99cfea6b4c15af12dec09110b25dbc7521363f78" + "reference": "e487dc725845ac914681e148d0e8ac479ad887ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/99cfea6b4c15af12dec09110b25dbc7521363f78", - "reference": "99cfea6b4c15af12dec09110b25dbc7521363f78", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/e487dc725845ac914681e148d0e8ac479ad887ec", + "reference": "e487dc725845ac914681e148d0e8ac479ad887ec", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "php-stubs/wordpress-stubs": "^4.7 || ^5.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", "phpstan/phpstan": "^1.6", "symfony/polyfill-php73": "^1.12.0" }, @@ -10058,7 +10058,7 @@ ], "support": { "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", - "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.1.1" + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.1.2" }, "funding": [ { @@ -10066,7 +10066,7 @@ "type": "custom" } ], - "time": "2022-05-11T18:41:40+00:00" + "time": "2022-06-21T10:51:00+00:00" }, { "name": "theseer/tokenizer", diff --git a/wp-content/plugins/core/functions/templates.php b/wp-content/plugins/core/functions/templates.php index 9e22b08c0..6fe63aaee 100644 --- a/wp-content/plugins/core/functions/templates.php +++ b/wp-content/plugins/core/functions/templates.php @@ -1,5 +1,7 @@ container()->get( Block_Component::class )->render( $block_class, $model ); + } +} diff --git a/wp-content/plugins/core/src/Blocks/Block_Component.php b/wp-content/plugins/core/src/Blocks/Block_Component.php new file mode 100644 index 000000000..5e7efe656 --- /dev/null +++ b/wp-content/plugins/core/src/Blocks/Block_Component.php @@ -0,0 +1,87 @@ +container = $container; + $this->block_path = $block_path; + } + + public function render( string $block_class, Block_Model $model ): void { + /** @var \Tribe\Libs\ACF\Block_Config $block_config */ + $block_config = $this->container->make( $block_class ); + $attributes = $block_config->get_block()->get_attributes(); + + $controller = $this->container->make( $attributes['controller'], [ + 'model' => $model, + ] ); + + $file_path = sprintf( $this->block_path, $attributes['view'] ); + $path = locate_template( $file_path . '.php' ); + + if ( ! file_exists( $path ) ) { + if ( ! WP_DEBUG ) { + return; + } + echo '
';
+			print_r( $block_config );
+			echo '
'; + + return; + } + + $this->load_template( $path, (array) apply_filters( 'tribe/project/block/view/data', [ + 'c' => $controller, + 'block' => $block_config, + 'is_preview' => $model->is_preview(), + 'post_id' => 0, + ], $block_config, $model, $controller ) ); + } + + /** + * A better version of load_template. + * + * @param string $path The path to the view to load. + * @param array $data The data to pass to the view. + * + * @see \load_template() + * + * @return void + */ + protected function load_template( string $path, array $data = [] ): void { + global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; + + extract( $data, EXTR_SKIP ); + + if ( is_array( $wp_query->query_vars ) ) { + /* + * This use of extract() cannot be removed. There are many possible ways that + * templates could depend on variables that it creates existing, and no way to + * detect and deprecate it. + * + * Passing the EXTR_SKIP flag is the safest option, ensuring globals and + * function variables cannot be overwritten. + */ + // phpcs:ignore WordPress.PHP.DontExtract.extract_extract + extract( $wp_query->query_vars, EXTR_SKIP ); + } + + if ( isset( $s ) ) { + $s = esc_attr( $s ); + } + + include $path; + } + +} diff --git a/wp-content/plugins/core/src/Blocks/Block_View_Factory.php b/wp-content/plugins/core/src/Blocks/Block_View_Factory.php new file mode 100644 index 000000000..0f733162f --- /dev/null +++ b/wp-content/plugins/core/src/Blocks/Block_View_Factory.php @@ -0,0 +1,111 @@ +container = $container; + $this->block_path = $block_path; + } + + /** + * Build the block model, controller and render the block view. + * + * @filter tribe/project/block/render + * + * @param array $block + * @param string $content + * @param bool $is_preview + * @param int $post_id + * @param \WP_Block|null $WP_block + * @param array $context + * + * @throws \DI\DependencyException + * @throws \DI\NotFoundException + */ + public function render_template( array $block, string $content, bool $is_preview, int $post_id, ?WP_Block $WP_block, array $context = [] ): void { + $fields = $WP_block ? ( $WP_block->parsed_block['attrs'] ?? [] ) : []; + $fields = array_merge( $fields, (array) get_fields() ); + + $model = $this->container->make( $block['model'], [ + 'fields' => $fields, + ] ); + + $controller = $this->container->make( $block['controller'], [ + 'model' => $model, + ] ); + + $file_path = sprintf( $this->block_path, $block['view'] ); + $path = locate_template( $file_path . '.php' ); + + if ( ! file_exists( $path ) ) { + if ( ! WP_DEBUG ) { + return; + } + echo '
';
+			print_r( $block );
+			print_r( $content );
+			print_r( $is_preview );
+			print_r( $post_id );
+			echo '
'; + + return; + } + + $this->load_template( $path, (array) apply_filters( 'tribe/project/block/view/data', [ + 'c' => $controller, + 'block' => $block, + 'is_preview' => $is_preview, + 'post_id' => $post_id, + 'context' => $context, + ], $block, $model, $controller ) ); + } + + /** + * A better version of load_template. + * + * @param string $path The path to the view to load. + * @param array $data The data to pass to the view. + * + * @see \load_template() + * + * @return void + */ + protected function load_template( string $path, array $data = [] ): void { + global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; + + extract( $data, EXTR_SKIP ); + + if ( is_array( $wp_query->query_vars ) ) { + /* + * This use of extract() cannot be removed. There are many possible ways that + * templates could depend on variables that it creates existing, and no way to + * detect and deprecate it. + * + * Passing the EXTR_SKIP flag is the safest option, ensuring globals and + * function variables cannot be overwritten. + */ + // phpcs:ignore WordPress.PHP.DontExtract.extract_extract + extract( $wp_query->query_vars, EXTR_SKIP ); + } + + if ( isset( $s ) ) { + $s = esc_attr( $s ); + } + + include $path; + } + +} diff --git a/wp-content/plugins/core/src/Blocks/Blocks_Definer.php b/wp-content/plugins/core/src/Blocks/Blocks_Definer.php index c27906616..975b252ae 100644 --- a/wp-content/plugins/core/src/Blocks/Blocks_Definer.php +++ b/wp-content/plugins/core/src/Blocks/Blocks_Definer.php @@ -11,8 +11,6 @@ use Tribe\Project\Blocks\Types\Content_Loop\Content_Loop; use Tribe\Project\Blocks\Types\Gallery_Grid\Gallery_Grid; use Tribe\Project\Blocks\Types\Gallery_Slider\Gallery_Slider; -use Tribe\Project\Blocks\Types\Hero\Hero; -use Tribe\Project\Blocks\Types\Icon_Grid\Icon_Grid; use Tribe\Project\Blocks\Types\Interstitial\Interstitial; use Tribe\Project\Blocks\Types\Lead_Form\Lead_Form; use Tribe\Project\Blocks\Types\Links\Links; @@ -23,16 +21,20 @@ use Tribe\Project\Blocks\Types\Spacer\Spacer; use Tribe\Project\Blocks\Types\Stats\Stats; use Tribe\Project\Blocks\Types\Tabs\Tabs; +use Tribe\Project\Templates\Components\blocks\hero\src\Hero; +use Tribe\Project\Templates\Components\blocks\icon_grid\src\Icon_Grid; class Blocks_Definer implements Definer_Interface { - public const DENY_LIST = 'blocks.deny_list'; - public const STYLES = 'blocks.style_overrides'; - public const TYPES = 'blocks.types'; + public const DENY_LIST = 'blocks.deny_list'; + public const STYLES = 'blocks.style_overrides'; + public const TYPES = 'blocks.types'; + public const BLOCK_PATH = 'blocks.block_path'; public function define(): array { return [ - self::TYPES => DI\add( [ + // TODO: probably move this part of the definition to the theme. + self::TYPES => DI\add( [ DI\get( Accordion::class ), DI\get( Buttons::class ), DI\get( Card_Grid::class ), @@ -60,7 +62,7 @@ public function define(): array { * * @see: https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/#using-a-deny-list */ - self::DENY_LIST => [ + self::DENY_LIST => [ 'core/archives', 'core/button', 'core/buttons', @@ -90,7 +92,7 @@ public function define(): array { * * TODO: Create a proper thumbnail of the style for the block editor: http://p.tri.be/dmsAwK */ - self::STYLES => DI\add( [ + self::STYLES => DI\add( [ DI\factory( static function () { return new Block_Style_Override( [ 'core/paragraph' ], [ [ @@ -113,7 +115,12 @@ public function define(): array { } ), ] ), - Block_Deny_List::class => DI\autowire()->constructor( DI\get( self::DENY_LIST ) ), + Block_Deny_List::class => DI\autowire()->constructor( DI\get( self::DENY_LIST ) ), + + // TODO: likely to update this path out of components, since a block isn't technically a component + self::BLOCK_PATH => DI\string( 'components/blocks/%1$s/%1$s' ), + Block_View_Factory::class => DI\autowire()->constructorParameter( 'block_path', DI\get( self::BLOCK_PATH ) ), + Block_Component::class => DI\autowire()->constructorParameter( 'block_path', DI\get( self::BLOCK_PATH ) ), ]; } diff --git a/wp-content/plugins/core/src/Blocks/Blocks_Subscriber.php b/wp-content/plugins/core/src/Blocks/Blocks_Subscriber.php index 1428dff02..1467eb3b8 100644 --- a/wp-content/plugins/core/src/Blocks/Blocks_Subscriber.php +++ b/wp-content/plugins/core/src/Blocks/Blocks_Subscriber.php @@ -3,7 +3,6 @@ namespace Tribe\Project\Blocks; use Tribe\Libs\ACF\Block_Registrar; -use Tribe\Libs\ACF\Block_Renderer; use Tribe\Libs\Container\Abstract_Subscriber; class Blocks_Subscriber extends Abstract_Subscriber { @@ -16,8 +15,8 @@ public function register(): void { }, 10, 1 ); add_action( 'tribe/project/block/render', function ( ...$args ): void { - $this->container->get( Block_Renderer::class )->render_template( ...$args ); - }, 10, 4 ); + $this->container->get( Block_View_Factory::class )->render_template( ...$args ); + }, 10, 6 ); /** * Adds the deny list to the JS_Config class. diff --git a/wp-content/plugins/core/src/Blocks/Contracts/Block_Controller.php b/wp-content/plugins/core/src/Blocks/Contracts/Block_Controller.php new file mode 100644 index 000000000..41bad8583 --- /dev/null +++ b/wp-content/plugins/core/src/Blocks/Contracts/Block_Controller.php @@ -0,0 +1,10 @@ +classes ); + } + + /** + * Get any block attributes from the block editor. + * + * @return array|string[] + */ + public function get_attrs(): array { + $attrs = []; + + // "HTML Anchor" attribute + if ( ! empty( $this->anchor ) ) { + $attrs['id'] = $this->anchor; + } + + return $attrs; + } + + public function is_preview(): bool { + return $this->mode === 'preview'; + } + +} diff --git a/wp-content/plugins/core/src/Blocks/Types/Base_Model.php b/wp-content/plugins/core/src/Blocks/Types/Base_Model.php index 9778a0181..22b76ea37 100644 --- a/wp-content/plugins/core/src/Blocks/Types/Base_Model.php +++ b/wp-content/plugins/core/src/Blocks/Types/Base_Model.php @@ -2,6 +2,9 @@ namespace Tribe\Project\Blocks\Types; +/** + * @TODO this would no longer be needed + */ abstract class Base_Model { /** diff --git a/wp-content/plugins/core/src/Blocks/Types/Hero/Hero_Model.php b/wp-content/plugins/core/src/Blocks/Types/Hero/Hero_Model.php deleted file mode 100644 index 6496889e7..000000000 --- a/wp-content/plugins/core/src/Blocks/Types/Hero/Hero_Model.php +++ /dev/null @@ -1,26 +0,0 @@ - $this->get_attrs(), - Hero_Block_Controller::CLASSES => $this->get_classes(), - Hero_Block_Controller::LAYOUT => $this->get( Hero::LAYOUT, Hero::LAYOUT_LEFT ), - Hero_Block_Controller::MEDIA => new Image( $this->get( Hero::IMAGE, [] ) ), - Hero_Block_Controller::TITLE => $this->get( Hero::TITLE, '' ), - Hero_Block_Controller::LEADIN => $this->get( Hero::LEAD_IN, '' ), - Hero_Block_Controller::DESCRIPTION => $this->get( Hero::DESCRIPTION, '' ), - Hero_Block_Controller::CTA => new Cta( $this->get( Cta_Field::GROUP_CTA, [] ) ), - ]; - } - -} diff --git a/wp-content/plugins/core/src/Blocks/Types/Icon_Grid/Icon_Grid_Model.php b/wp-content/plugins/core/src/Blocks/Types/Icon_Grid/Icon_Grid_Model.php deleted file mode 100644 index ade2b26f7..000000000 --- a/wp-content/plugins/core/src/Blocks/Types/Icon_Grid/Icon_Grid_Model.php +++ /dev/null @@ -1,32 +0,0 @@ - $this->get_attrs(), - Icon_Grid_Controller::CLASSES => $this->get_classes(), - Icon_Grid_Controller::LAYOUT => $this->get( Icon_Grid::LAYOUT, [] ), - Icon_Grid_Controller::TITLE => $this->get( Icon_Grid::TITLE, '' ), - Icon_Grid_Controller::LEADIN => $this->get( Icon_Grid::LEADIN, '' ), - Icon_Grid_Controller::DESCRIPTION => $this->get( Icon_Grid::DESCRIPTION, '' ), - Icon_Grid_Controller::CTA => new Cta( $this->get( Cta_Field::GROUP_CTA, [] ) ), - Icon_Grid_Controller::ICONS => Icon_Collection::create( $this->get( Icon_Grid::ICONS, [] ) ), - ]; - } - -} diff --git a/wp-content/themes/core/blocks/hero/hero.php b/wp-content/themes/core/blocks/hero/hero.php deleted file mode 100644 index 42ba3d445..000000000 --- a/wp-content/themes/core/blocks/hero/hero.php +++ /dev/null @@ -1,14 +0,0 @@ -container()->make( Hero_Model::class, $args ); - -get_template_part( - 'components/blocks/hero/hero', - '', - $model->get_data() -); diff --git a/wp-content/themes/core/blocks/icongrid/icongrid.php b/wp-content/themes/core/blocks/icongrid/icongrid.php deleted file mode 100644 index 95c0df432..000000000 --- a/wp-content/themes/core/blocks/icongrid/icongrid.php +++ /dev/null @@ -1,14 +0,0 @@ -container()->make( Icon_Grid_Model::class, $args ); - -get_template_part( - 'components/blocks/icon_grid/icon_grid', - '', - $model->get_data() -); diff --git a/wp-content/themes/core/components/blocks/hero/Hero_Block_Controller.php b/wp-content/themes/core/components/blocks/hero/Hero_Block_Controller.php deleted file mode 100644 index 2bde4df08..000000000 --- a/wp-content/themes/core/components/blocks/hero/Hero_Block_Controller.php +++ /dev/null @@ -1,222 +0,0 @@ -parse_args( $args ); - - $this->attrs = (array) $args[ self::ATTRS ]; - $this->classes = (array) $args[ self::CLASSES ]; - $this->container_classes = (array) $args[ self::CONTAINER_CLASSES ]; - $this->content_classes = (array) $args[ self::CONTENT_CLASSES ]; - $this->cta = $args[ self::CTA ]; - $this->description = (string) $args[ self::DESCRIPTION ]; - $this->layout = (string) $args[ self::LAYOUT ]; - $this->leadin = (string) $args[ self::LEADIN ]; - $this->media = $args[ self::MEDIA ]; - $this->media_classes = (array) $args[ self::MEDIA_CLASSES ]; - $this->title = (string) $args[ self::TITLE ]; - } - - public function get_classes(): string { - $this->classes[] = 'c-block--layout-' . $this->layout; - - return Markup_Utils::class_attribute( $this->classes ); - } - - public function get_attrs(): string { - return Markup_Utils::concat_attrs( $this->attrs ); - } - - public function get_container_classes(): string { - return Markup_Utils::class_attribute( $this->container_classes ); - } - - public function get_media_classes(): string { - return Markup_Utils::class_attribute( $this->media_classes ); - } - - public function get_content_classes(): string { - return Markup_Utils::class_attribute( $this->content_classes ); - } - - public function get_content_args(): array { - if ( empty( $this->title ) && empty( $this->description ) ) { - return []; - } - - return [ - Content_Block_Controller::TAG => 'header', - Content_Block_Controller::LEADIN => $this->get_leadin(), - Content_Block_Controller::TITLE => $this->get_title(), - Content_Block_Controller::CONTENT => $this->get_content(), - Content_Block_Controller::CTA => $this->get_cta(), - Content_Block_Controller::LAYOUT => $this->layout, - Content_Block_Controller::CLASSES => [ - 'c-block__content-block', - 'c-block__header', - 'b-hero__content-container', - 't-theme--light', - ], - ]; - } - - public function get_image_args(): array { - if ( ! $this->media->id ) { - return []; - } - - return [ - Image_Controller::IMG_ID => $this->media->id, - Image_Controller::AS_BG => true, - Image_Controller::AUTO_SHIM => false, - Image_Controller::USE_LAZYLOAD => true, - Image_Controller::WRAPPER_TAG => 'div', - Image_Controller::CLASSES => [ 'b-hero__figure', 'c-image--bg', 'c-image--overlay' ], - Image_Controller::IMG_CLASSES => [ 'b-hero__img' ], - Image_Controller::SRC_SIZE => Image_Sizes::CORE_FULL, - Image_Controller::SRCSET_SIZES => [ - Image_Sizes::CORE_FULL, - Image_Sizes::CORE_MOBILE, - ], - ]; - } - - protected function defaults(): array { - return [ - self::ATTRS => [], - self::CLASSES => [ 'c-block--full-bleed' ], - self::CONTAINER_CLASSES => [], - self::CONTENT_CLASSES => [], - self::CTA => new Cta(), - self::DESCRIPTION => '', - self::LAYOUT => Hero_Block::LAYOUT_LEFT, - self::LEADIN => '', - self::MEDIA => new Image(), - self::MEDIA_CLASSES => [], - self::TITLE => '', - ]; - } - - protected function required(): array { - return [ - self::CLASSES => [ 'c-block', 'b-hero' ], - self::CONTAINER_CLASSES => [ 'b-hero__container', 'l-container' ], - self::CONTENT_CLASSES => [ 'b-hero__content' ], - self::MEDIA_CLASSES => [ 'b-hero__media' ], - ]; - } - - private function get_leadin(): Deferred_Component { - return defer_template_part( 'components/text/text', null, [ - Text_Controller::CLASSES => [ - 'c-block__leadin', - 'b-hero__leadin', - 'h6', - ], - Text_Controller::CONTENT => $this->leadin, - ] ); - } - - private function get_title(): Deferred_Component { - return defer_template_part( 'components/text/text', null, [ - Text_Controller::TAG => 'h2', - Text_Controller::CLASSES => [ - 'c-block__title', - 'b-hero__title', - 'h3', - ], - Text_Controller::CONTENT => $this->title, - ] ); - } - - private function get_content(): Deferred_Component { - return defer_template_part( 'components/container/container', null, [ - Container_Controller::CLASSES => [ - 'c-block__description', - 'b-hero__description', - 't-sink', - 's-sink', - ], - Container_Controller::CONTENT => $this->description, - ] ); - } - - private function get_cta(): Deferred_Component { - return defer_template_part( 'components/link/link', null, [ - Link_Controller::URL => $this->cta->link->url, - Link_Controller::CONTENT => $this->cta->link->title ?: $this->cta->link->url, - Link_Controller::TARGET => $this->cta->link->target, - Link_Controller::ADD_ARIA_LABEL => $this->cta->add_aria_label, - Link_Controller::ARIA_LABEL => $this->cta->aria_label, - Link_Controller::CLASSES => [ - 'c-block__cta-link', - 'a-btn', - 'a-btn--has-icon-after', - 'icon-arrow-right', - ], - ] ); - } - -} diff --git a/wp-content/themes/core/components/blocks/hero/hero.php b/wp-content/themes/core/components/blocks/hero/hero.php index b41f2c0a8..6f3a28751 100644 --- a/wp-content/themes/core/components/blocks/hero/hero.php +++ b/wp-content/themes/core/components/blocks/hero/hero.php @@ -1,11 +1,8 @@
get_classes(); ?> get_attrs(); ?>> diff --git a/wp-content/plugins/core/src/Blocks/Types/Hero/Hero.php b/wp-content/themes/core/components/blocks/hero/src/Hero.php similarity index 89% rename from wp-content/plugins/core/src/Blocks/Types/Hero/Hero.php rename to wp-content/themes/core/components/blocks/hero/src/Hero.php index 53dc5a70b..3c3785fa3 100644 --- a/wp-content/plugins/core/src/Blocks/Types/Hero/Hero.php +++ b/wp-content/themes/core/components/blocks/hero/src/Hero.php @@ -1,6 +1,6 @@ set_block( new Block( self::NAME, [ - 'title' => __( 'Hero', 'tribe' ), - 'description' => __( 'Hero block', 'tribe' ), + 'title' => esc_html__( 'Hero', 'tribe' ), + 'description' => esc_html__( 'Hero block', 'tribe' ), 'icon' => '', - 'keywords' => [ __( 'hero', 'tribe' ), __( 'display', 'tribe' ) ], + 'keywords' => [ esc_html__( 'hero', 'tribe' ), esc_html__( 'display', 'tribe' ) ], 'category' => 'layout', 'supports' => [ 'align' => false, 'anchor' => true, ], + 'model' => Hero_Model::class, + 'view' => 'hero', + 'controller' => Hero_Block_Controller::class, 'example' => [ 'attributes' => [ 'mode' => 'preview', @@ -97,7 +100,7 @@ public function add_fields(): void { $this->get_cta_field( self::NAME ) ); - $this->add_section( new Field_Section( self::SECTION_BACKGROUND, __( 'Background', 'tribe' ), 'accordion' ) ) + $this->add_section( new Field_Section( self::SECTION_BACKGROUND, esc_html__( 'Background', 'tribe' ), 'accordion' ) ) ->add_field( new Field( self::NAME . '_' . self::IMAGE, [ 'label' => esc_html__( 'Image', 'tribe' ), 'name' => self::IMAGE, @@ -110,7 +113,7 @@ public function add_fields(): void { ] ) ); - $this->add_section( new Field_Section( self::SECTION_APPEARANCE, __( 'Appearance', 'tribe' ), 'accordion' ) ) + $this->add_section( new Field_Section( self::SECTION_APPEARANCE, esc_html__( 'Appearance', 'tribe' ), 'accordion' ) ) ->add_field( new Field( self::NAME . '_' . self::LAYOUT, [ 'label' => __( 'Text Alignment', 'tribe' ), 'type' => 'button_group', diff --git a/wp-content/themes/core/components/blocks/hero/src/Hero_Block_Controller.php b/wp-content/themes/core/components/blocks/hero/src/Hero_Block_Controller.php new file mode 100644 index 000000000..7a22d498f --- /dev/null +++ b/wp-content/themes/core/components/blocks/hero/src/Hero_Block_Controller.php @@ -0,0 +1,139 @@ +model = $model; + } + + public function get_classes(): string { + $classes = $this->model->get_classes(); + $classes[] = 'c-block--layout-' . $this->model->layout; + + return Markup_Utils::class_attribute( $classes ); + } + + public function get_attrs(): string { + return Markup_Utils::concat_attrs( $this->model->get_attrs() ); + } + + public function get_container_classes(): string { + return Markup_Utils::class_attribute( $this->model->container_classes ); + } + + public function get_media_classes(): string { + return Markup_Utils::class_attribute( $this->model->media_classes ); + } + + public function get_content_classes(): string { + return Markup_Utils::class_attribute( $this->model->content_classes ); + } + + public function get_content_args(): array { + if ( empty( $this->title ) && empty( $this->description ) ) { + return []; + } + + return [ + Content_Block_Controller::TAG => 'header', + Content_Block_Controller::LEADIN => $this->get_leadin(), + Content_Block_Controller::TITLE => $this->get_title(), + Content_Block_Controller::CONTENT => $this->get_content(), + Content_Block_Controller::CTA => $this->get_cta(), + Content_Block_Controller::LAYOUT => $this->model->layout, + Content_Block_Controller::CLASSES => [ + 'c-block__content-block', + 'c-block__header', + 'b-hero__content-container', + 't-theme--light', + ], + ]; + } + + public function get_image_args(): array { + if ( ! $this->model->media->id ) { + return []; + } + + return [ + Image_Controller::IMG_ID => $this->model->media->id, + Image_Controller::AS_BG => true, + Image_Controller::AUTO_SHIM => false, + Image_Controller::USE_LAZYLOAD => true, + Image_Controller::WRAPPER_TAG => 'div', + Image_Controller::CLASSES => [ 'b-hero__figure', 'c-image--bg', 'c-image--overlay' ], + Image_Controller::IMG_CLASSES => [ 'b-hero__img' ], + Image_Controller::SRC_SIZE => Image_Sizes::CORE_FULL, + Image_Controller::SRCSET_SIZES => [ + Image_Sizes::CORE_FULL, + Image_Sizes::CORE_MOBILE, + ], + ]; + } + + private function get_leadin(): Deferred_Component { + return defer_template_part( 'components/text/text', null, [ + Text_Controller::CLASSES => [ + 'c-block__leadin', + 'b-hero__leadin', + 'h6', + ], + Text_Controller::CONTENT => $this->model->leadin, + ] ); + } + + private function get_title(): Deferred_Component { + return defer_template_part( 'components/text/text', null, [ + Text_Controller::TAG => 'h2', + Text_Controller::CLASSES => [ + 'c-block__title', + 'b-hero__title', + 'h3', + ], + Text_Controller::CONTENT => $this->model->title, + ] ); + } + + private function get_content(): Deferred_Component { + return defer_template_part( 'components/container/container', null, [ + Container_Controller::CLASSES => [ + 'c-block__description', + 'b-hero__description', + 't-sink', + 's-sink', + ], + Container_Controller::CONTENT => $this->model->description, + ] ); + } + + private function get_cta(): Deferred_Component { + return defer_template_part( 'components/link/link', null, [ + Link_Controller::URL => $this->model->cta->link->url, + Link_Controller::CONTENT => $this->model->cta->link->title ?: $this->model->cta->link->url, + Link_Controller::TARGET => $this->model->cta->link->target, + Link_Controller::ADD_ARIA_LABEL => $this->model->cta->add_aria_label, + Link_Controller::ARIA_LABEL => $this->model->cta->aria_label, + Link_Controller::CLASSES => [ + 'c-block__cta-link', + 'a-btn', + 'a-btn--has-icon-after', + 'icon-arrow-right', + ], + ] ); + } + +} diff --git a/wp-content/themes/core/components/blocks/hero/src/Hero_Model.php b/wp-content/themes/core/components/blocks/hero/src/Hero_Model.php new file mode 100644 index 000000000..bf0a210d3 --- /dev/null +++ b/wp-content/themes/core/components/blocks/hero/src/Hero_Model.php @@ -0,0 +1,34 @@ +
get_classes(); ?> get_attrs(); ?>>
get_container_classes(); ?>> diff --git a/wp-content/plugins/core/src/Blocks/Types/Icon_Grid/Icon_Grid.php b/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid.php similarity index 91% rename from wp-content/plugins/core/src/Blocks/Types/Icon_Grid/Icon_Grid.php rename to wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid.php index c89afc29d..fde9c2064 100644 --- a/wp-content/plugins/core/src/Blocks/Types/Icon_Grid/Icon_Grid.php +++ b/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid.php @@ -1,6 +1,6 @@ set_block( new Block( self::NAME, [ - 'title' => __( 'Icon Grid', 'tribe' ), - 'description' => __( 'A grid layout block with icon selections', 'tribe' ), + 'title' => esc_html__( 'Icon Grid', 'tribe' ), + 'description' => esc_html__( 'A grid layout block with icon selections', 'tribe' ), 'icon' => '', - 'keywords' => [ __( 'icon', 'tribe' ), __( 'grid', 'tribe' ) ], + 'keywords' => [ esc_html__( 'icon', 'tribe' ), esc_html__( 'grid', 'tribe' ) ], 'category' => 'common', // core categories: common, formatting, layout, widgets, embed 'supports' => [ 'align' => false, 'anchor' => true, 'html' => false, ], + 'model' => Icon_Grid_Model::class, + 'view' => 'icon_grid', + 'controller' => Icon_Grid_Controller::class, ] ) ); } diff --git a/wp-content/themes/core/components/blocks/icon_grid/Icon_Grid_Controller.php b/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid_Controller.php similarity index 52% rename from wp-content/themes/core/components/blocks/icon_grid/Icon_Grid_Controller.php rename to wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid_Controller.php index 7b31f3b09..0c64d53ad 100644 --- a/wp-content/themes/core/components/blocks/icon_grid/Icon_Grid_Controller.php +++ b/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid_Controller.php @@ -1,10 +1,9 @@ parse_args( $args ); - - $this->attrs = (array) $args[ self::ATTRS ]; - $this->classes = (array) $args[ self::CLASSES ]; - $this->container_classes = (array) $args[ self::CONTAINER_CLASSES ]; - $this->content_classes = (array) $args[ self::CONTENT_CLASSES ]; - $this->cta = $args[ self::CTA ]; - $this->description = (string) $args[ self::DESCRIPTION ]; - $this->icons = $args[ self::ICONS ]; - $this->layout = (string) $args[ self::LAYOUT ]; - $this->leadin = (string) $args[ self::LEADIN ]; - $this->title = (string) $args[ self::TITLE ]; + +class Icon_Grid_Controller implements Block_Controller { + + private Icon_Grid_Model $model; + + public function __construct( Icon_Grid_Model $model ) { + $this->model = $model; } public function get_classes(): string { - return Markup_Utils::class_attribute( $this->classes ); + return Markup_Utils::class_attribute( $this->model->get_classes() ); } public function get_attrs(): string { - return Markup_Utils::concat_attrs( $this->attrs ); + return Markup_Utils::concat_attrs( $this->model->get_attrs() ); } public function get_container_classes(): string { - $this->container_classes[] = 'layout-' . $this->layout; - - return Markup_Utils::class_attribute( $this->container_classes ); + return Markup_Utils::class_attribute( [ + 'layout-' . $this->model->layout, + ] ); } public function get_content_classes(): string { - $this->content_classes[] = 'g-3-up'; - $this->content_classes[] = 'g-centered'; - - return Markup_Utils::class_attribute( $this->content_classes ); + return Markup_Utils::class_attribute( [ + 'g-3-up', + 'g-centered', + ] ); } public function get_header_args(): array { - if ( empty( $this->title ) && empty( $this->description ) ) { + if ( empty( $this->model->title ) && empty( $this->model->description ) ) { return []; } @@ -112,11 +63,11 @@ public function get_header_args(): array { public function get_cta(): Deferred_Component { return defer_template_part( 'components/link/link', null, [ - Link_Controller::URL => $this->cta->link->url, - Link_Controller::CONTENT => $this->cta->link->title ?: $this->cta->link->url, - Link_Controller::TARGET => $this->cta->link->target, - Link_Controller::ADD_ARIA_LABEL => $this->cta->add_aria_label, - Link_Controller::ARIA_LABEL => $this->cta->aria_label, + Link_Controller::URL => $this->model->cta->link->url, + Link_Controller::CONTENT => $this->model->cta->link->title ?: $this->model->cta->link->url, + Link_Controller::TARGET => $this->model->cta->link->target, + Link_Controller::ADD_ARIA_LABEL => $this->model->cta->add_aria_label, + Link_Controller::ARIA_LABEL => $this->model->cta->aria_label, Link_Controller::CLASSES => [ 'c-block__cta-link', 'a-btn', @@ -129,11 +80,11 @@ public function get_cta(): Deferred_Component { public function get_icon_card_args(): array { $cards = []; - if ( ! $this->icons->count() ) { + if ( ! $this->model->icons->count() ) { return $cards; } - foreach ( $this->icons as $card ) { + foreach ( $this->model->icons as $card ) { $cards[] = [ Card_Controller::STYLE => Card_Controller::STYLE_PLAIN, Card_Controller::TAG => 'li', @@ -187,62 +138,37 @@ public function get_icon_card_args(): array { return $cards; } - protected function defaults(): array { - return [ - self::ATTRS => [], - self::CLASSES => [], - self::CONTAINER_CLASSES => [], - self::CONTENT_CLASSES => [], - self::CTA => new Cta(), - self::DESCRIPTION => '', - self::ICONS => new Icon_Collection(), - self::LAYOUT => '', - self::LEADIN => '', - self::TITLE => '', - ]; - } - - protected function required(): array { - return [ - self::CLASSES => [ - 'c-block', - 'b-icon-grid', - ], - self::CONTAINER_CLASSES => [ 'l-container' ], - ]; - } - private function get_leadin(): Deferred_Component { - return defer_template_part( 'components/text/text', null, [ + return defer_template_part( 'components/text/text', '', [ Text_Controller::CLASSES => [ 'c-block__leadin', 'b-icon-grid__leadin', 'h6', ], - Text_Controller::CONTENT => $this->leadin, + Text_Controller::CONTENT => $this->model->leadin, ] ); } private function get_title(): Deferred_Component { - return defer_template_part( 'components/text/text', null, [ + return defer_template_part( 'components/text/text', '', [ Text_Controller::TAG => 'h2', Text_Controller::CLASSES => [ 'c-block__title', 'h3', ], - Text_Controller::CONTENT => $this->title, + Text_Controller::CONTENT => $this->model->title, ] ); } private function get_content(): Deferred_Component { - return defer_template_part( 'components/container/container', null, [ + return defer_template_part( 'components/container/container', '', [ Container_Controller::CLASSES => [ 'c-block__description', 'b-icon-grid__description', 't-sink', 's-sink', ], - Container_Controller::CONTENT => $this->description, + Container_Controller::CONTENT => $this->model->description, ] ); } diff --git a/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid_Model.php b/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid_Model.php new file mode 100644 index 000000000..b808e1ff4 --- /dev/null +++ b/wp-content/themes/core/components/blocks/icon_grid/src/Icon_Grid_Model.php @@ -0,0 +1,18 @@ +sidebar_id = (string) $args[ self::SIDEBAR_ID ]; } + /** + * @TODO remove this example. + */ + public function get_hero_model(): Hero_Model { + $model = new Hero_Model(); + $model->title = 'A Hero Block title'; + $model->description = 'A Hero Block description'; + $model->content_classes = [ + 'some-class', + ]; + $model->media = new Image( (array) acf_get_attachment( ( new WP_Query( [ + 'post_type' => 'attachment', + 'post_status' => 'inherit', + 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png', + 'posts_per_page' => 1, + 'no_found_rows' => true, + 'fields' => 'ids', + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false, + ] ) )->posts[0] ?? 0 ) ); + + return $model; + } + public function get_subheader_args(): array { global $post; diff --git a/wp-content/themes/core/routes/single/single.php b/wp-content/themes/core/routes/single/single.php index 04967dfd0..e03d16b13 100644 --- a/wp-content/themes/core/routes/single/single.php +++ b/wp-content/themes/core/routes/single/single.php @@ -1,5 +1,6 @@
+ get_hero_model() ); + ?> get_subheader_args() ); ?>