diff --git a/build.js b/build.js index 08c3ac3..f04ad40 100755 --- a/build.js +++ b/build.js @@ -45,14 +45,13 @@ console.log('--------------------\nDone!'); // export async function buildExportFiles(platform) { - if (['wordpress', 'php'].includes(platform.name)) { - - if (platform.name === 'wordpress') { - await buildWordPress(blockName); + if (platform.name.startsWith('wordpress')) { + if (platform.name === 'wordpress-blocks') { + await buildWordPress(blockName, true); + } else if (platform.name === 'wordpress-elementor') { + await buildWordPress(blockName, false, true); } else { - if (platform.name === 'wordpress-blocks') { - await buildWordPress(blockName, true); - } + await buildWordPress(blockName); } } else if (platform.name === 'hubspot-email') { await buildHubspotEmail(blockName) diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php index f94185a..e9ecd54 100644 --- a/platforms/wordpress/templates/Template_Basic_Component.php +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -36,4 +36,11 @@ class <%= blockClassModel %>_Component { echo apply_filters( 'the_content', wpautop( $output ) ); } + <% if (isElementor) { %>function register_elementor_widget( $widgets_manager ): void { + require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php"; + $widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() ); + }<% } %> + } + +// ( new <%= blockClassModel %>_Component() ); // Initialization diff --git a/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php b/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php new file mode 100644 index 0000000..3c1d4b6 --- /dev/null +++ b/platforms/wordpress/templates/helpers/Template_Elementor_Widget.php @@ -0,0 +1,60 @@ +\<%= blockClassModel %>\Helpers; + +class <%= blockClassModel %>_Elementor_Widget extends \Elementor\Widget_Base { + const PLUGIN_NAME = '<%= blockFilename %>'; + + public function get_name() { + return self::PLUGIN_NAME; + } + + public function get_title() { + return '<%= blockClassModel %>'; + } + + public function get_icon() { + return 'eicon-plus-square-o'; + } + + 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(); + } + + function get_style_depends() { + return [ '<%= blockFilename %>' ]; + } + + function get_script_depends() { + return [ 'script-<%= blockFilename %>' ]; + } + + protected function render() { + $settings = $this->get_settings_for_display(); + + $component = new \AXEWEB_Blocks\Blocks\Scytale\<%= blockClassModel %>\<%= blockClassModel %>_Component(); + + $args = self::prepare( $settings ); + $component->render( $args ); + } + + public static function prepare( $args ): array { + // Prepare $args for render function. + return $args; + } +} diff --git a/platforms/wordpress/wordpress-adapter.js b/platforms/wordpress/wordpress-adapter.js index ffd870d..119efd3 100644 --- a/platforms/wordpress/wordpress-adapter.js +++ b/platforms/wordpress/wordpress-adapter.js @@ -11,7 +11,7 @@ const __dirname = path.dirname(__filename); const {modulesPath, projectPath} = getConfigs(); -export async function buildWordPress(blockName, isBlock = false) { +export async function buildWordPress(blockName, isBlock = false, isElementor = false) { const distPath = path.join(projectPath, 'exports', 'wordpress'); // await mkdir(distPath, {recursive: true}) await mkdir(path.join(distPath, 'templates'), {recursive: true}) @@ -38,6 +38,7 @@ export async function buildWordPress(blockName, isBlock = false) { include_native_gutenberg_block: false, include_script: true, include_elementor_widget: false, + isElementor, }); const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : ''; @@ -73,6 +74,16 @@ export async function buildWordPress(blockName, isBlock = false) { generatorsPath: path.join(__dirname), }); + if(isElementor){ + await createFiles(data, [{ + from: `templates/helpers/Template_Elementor_Widget.php`, + to: `helpers/${data.blockClassModel}_Elementor_Widget.php`, + }], { + pathDist: distPath, + generatorsPath: path.join(__dirname) + }); + } + if (isBlock) { await createFiles(data, [{ from: `templates/Template_Component.php`,