Browse Source

Added Basic Elementor widget logic.

test-gpt-generated
Roman Axelrod 3 years ago
parent
commit
4d1d2337bf
  1. 13
      build.js
  2. 7
      platforms/wordpress/templates/Template_Basic_Component.php
  3. 60
      platforms/wordpress/templates/helpers/Template_Elementor_Widget.php
  4. 13
      platforms/wordpress/wordpress-adapter.js

13
build.js

@ -45,14 +45,13 @@ console.log('--------------------\nDone!');
// //
export async function buildExportFiles(platform) { export async function buildExportFiles(platform) {
if (['wordpress', 'php'].includes(platform.name)) { if (platform.name.startsWith('wordpress')) {
if (platform.name === 'wordpress-blocks') {
if (platform.name === 'wordpress') { await buildWordPress(blockName, true);
await buildWordPress(blockName); } else if (platform.name === 'wordpress-elementor') {
await buildWordPress(blockName, false, true);
} else { } else {
if (platform.name === 'wordpress-blocks') { await buildWordPress(blockName);
await buildWordPress(blockName, true);
}
} }
} else if (platform.name === 'hubspot-email') { } else if (platform.name === 'hubspot-email') {
await buildHubspotEmail(blockName) await buildHubspotEmail(blockName)

7
platforms/wordpress/templates/Template_Basic_Component.php

@ -36,4 +36,11 @@ class <%= blockClassModel %>_Component {
echo apply_filters( 'the_content', wpautop( $output ) ); 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

60
platforms/wordpress/templates/helpers/Template_Elementor_Widget.php

@ -0,0 +1,60 @@
<?php
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= 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;
}
}

13
platforms/wordpress/wordpress-adapter.js

@ -11,7 +11,7 @@ const __dirname = path.dirname(__filename);
const {modulesPath, projectPath} = getConfigs(); 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'); const distPath = path.join(projectPath, 'exports', 'wordpress');
// await mkdir(distPath, {recursive: true}) // await mkdir(distPath, {recursive: true})
await mkdir(path.join(distPath, 'templates'), {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_native_gutenberg_block: false,
include_script: true, include_script: true,
include_elementor_widget: false, include_elementor_widget: false,
isElementor,
}); });
const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : ''; const backPath = modulesPath ? modulesPath.split('/').map(() => '..').join('/') : '';
@ -73,6 +74,16 @@ export async function buildWordPress(blockName, isBlock = false) {
generatorsPath: path.join(__dirname), 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) { if (isBlock) {
await createFiles(data, [{ await createFiles(data, [{
from: `templates/Template_Component.php`, from: `templates/Template_Component.php`,

Loading…
Cancel
Save