From 50d743140ba6a171574678fa95c26efc627bd78a Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Mon, 2 Jan 2023 12:48:49 +0200 Subject: [PATCH 1/2] Updated Build Template of Elementor block. --- platforms/wordpress/templates/Template_Basic_Component.php | 6 +++++- .../templates/helpers/Template_Elementor_Widget.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php index 3686f8f..2c57538 100644 --- a/platforms/wordpress/templates/Template_Basic_Component.php +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -2,7 +2,7 @@ namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>; -class <%= blockClassModel %>_Component <% if (isComponentManager) { %>extends \Core\Component <% } %>{ +class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) { %>extends \Core\Component <% } %>{ const VERSION = '<%= version %>';<% if (isComponentManager) { %> public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';<% } %> @@ -34,6 +34,10 @@ class <%= blockClassModel %>_Component <% if (isComponentManager) { %>extends \C return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output ); }<% if (isElementor) { %> + function register_custom_logic(): void { + add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] ); + } + function register_elementor_widget( $widgets_manager ): void { require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php"; $widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() ); diff --git a/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php b/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php index 3c1d4b6..098bfb7 100644 --- a/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php +++ b/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php @@ -47,7 +47,7 @@ class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base { protected function render() { $settings = $this->get_settings_for_display(); - $component = new \AXEWEB_Blocks\Blocks\Scytale\<%= blockClassModel %>\<%= blockClassModel %>_Component(); + $component = new \AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>\<%= blockClassModel %>_Component(); $args = self::prepare( $settings ); $component->render( $args ); From df7866b8b5ea7dac82fae3571eadec4a40798081 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Mon, 2 Jan 2023 14:23:11 +0200 Subject: [PATCH 2/2] Updated Build Template of Elementor block. --- .../templates/Template_Basic_Component.php | 3 ++- .../helpers/Template_Elementor_Widget.php | 22 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php index 2c57538..6c297f6 100644 --- a/platforms/wordpress/templates/Template_Basic_Component.php +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -7,7 +7,8 @@ class <%= blockClassModel %>_Component <% if (isComponentManager || isElementor) public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';<% } %> <% if (!isComponentManager) { %>public function __construct() { - // add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] ); + <% if (isElementor) { %>parent::__construct(); + <% } %>// add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] ); add_action( 'after_setup_theme', [ $this, 'register_assets' ] ); } diff --git a/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php b/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php index 098bfb7..74ef4ef 100644 --- a/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php +++ b/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php @@ -18,30 +18,16 @@ class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base { } protected function _register_controls() { - $this->start_controls_section( 'section_content', [ 'label' => 'Content' ] ); - - $repeater = new \Elementor\Repeater(); - - // $repeater->add_control( - // 'video_url', [ - // 'label' => 'YouTube URL', - // 'type' => \Elementor\Controls_Manager::URL, - // 'label_block' => true, - // 'condition' => [ - // 'type' => 'video', - // ], - // ] - // ); - - $this->end_controls_section(); + $block_data = \Core\Block::get_block_data( __DIR__ . '/../<%= blockFilename %>.block.json' ); + \Core\Elementor_Block::register_groups( $block_data, $this ); } function get_style_depends() { - return [ '<%= blockFilename %>' ]; + return [ 'block-<%= blockFilename %>' ]; } function get_script_depends() { - return [ 'script-<%= blockFilename %>' ]; + return [ 'block-<%= blockFilename %>' ]; } protected function render() {