| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Onboarding; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Blocks\Block_Helper; |
| 7 |
use JFB_Components\Module\Base_Module_After_Install_It; |
| 8 |
use JFB_Components\Module\Base_Module_Dir_It; |
| 9 |
use JFB_Components\Module\Base_Module_Dir_Trait; |
| 10 |
use JFB_Components\Module\Base_Module_Handle_It; |
| 11 |
use JFB_Components\Module\Base_Module_Handle_Trait; |
| 12 |
use JFB_Components\Module\Base_Module_It; |
| 13 |
use JFB_Components\Module\Base_Module_Url_It; |
| 14 |
use JFB_Components\Module\Base_Module_Url_Trait; |
| 15 |
use JFB_Modules\Onboarding\Use_Form\Use_Form; |
| 16 |
|
| 17 |
// If this file is called directly, abort. |
| 18 |
if ( ! defined( 'WPINC' ) ) { |
| 19 |
die; |
| 20 |
} |
| 21 |
|
| 22 |
class Module implements |
| 23 |
Base_Module_It, |
| 24 |
Base_Module_Url_It, |
| 25 |
Base_Module_Dir_It, |
| 26 |
Base_Module_Handle_It, |
| 27 |
Base_Module_After_Install_It { |
| 28 |
|
| 29 |
use Base_Module_Handle_Trait; |
| 30 |
use Base_Module_Url_Trait; |
| 31 |
use Base_Module_Dir_Trait; |
| 32 |
|
| 33 |
/** |
| 34 |
* @var Preview |
| 35 |
*/ |
| 36 |
private $preview; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var Use_Form |
| 40 |
*/ |
| 41 |
private $use_form; |
| 42 |
|
| 43 |
public function rep_item_id() { |
| 44 |
return 'onboarding'; |
| 45 |
} |
| 46 |
|
| 47 |
public function condition(): bool { |
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
public function on_install() { |
| 52 |
$this->preview = new Preview(); |
| 53 |
$this->use_form = new Use_Form(); |
| 54 |
} |
| 55 |
|
| 56 |
public function on_uninstall() { |
| 57 |
unset( |
| 58 |
$this->preview, |
| 59 |
$this->use_form |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
public function init_hooks() { |
| 64 |
add_action( |
| 65 |
'jet-form-builder/editor-assets/before', |
| 66 |
array( $this, 'editor_assets_before' ), |
| 67 |
20 |
| 68 |
); |
| 69 |
add_action( |
| 70 |
'jet-form-builder/editor-assets/before', |
| 71 |
array( $this, 'editor_assets_package_before' ), |
| 72 |
0 |
| 73 |
); |
| 74 |
add_filter( |
| 75 |
'jet-form-builder/post-type/args', |
| 76 |
array( $this, 'add_default_fields_to_form' ), |
| 77 |
99 |
| 78 |
); |
| 79 |
add_action( |
| 80 |
'jet-form-builder/render-preview', |
| 81 |
array( $this, 'enqueue_frontend_assets' ) |
| 82 |
); |
| 83 |
$this->get_preview()->init_hooks(); |
| 84 |
$this->get_use_form()->init_hooks(); |
| 85 |
} |
| 86 |
|
| 87 |
public function remove_hooks() { |
| 88 |
remove_action( |
| 89 |
'jet-form-builder/editor-assets/before', |
| 90 |
array( $this, 'editor_assets_before' ) |
| 91 |
); |
| 92 |
remove_action( |
| 93 |
'jet-form-builder/editor-package/before', |
| 94 |
array( $this, 'editor_assets_package_before' ) |
| 95 |
); |
| 96 |
remove_filter( |
| 97 |
'jet-form-builder/post-type/args', |
| 98 |
array( $this, 'add_default_fields_to_form' ), |
| 99 |
99 |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
public function editor_assets_before() { |
| 104 |
$script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' ); |
| 105 |
|
| 106 |
wp_enqueue_script( |
| 107 |
$this->get_handle(), |
| 108 |
$this->get_url( 'assets/build/editor.js' ), |
| 109 |
$script_asset['dependencies'], |
| 110 |
$script_asset['version'], |
| 111 |
true |
| 112 |
); |
| 113 |
} |
| 114 |
|
| 115 |
public function editor_assets_package_before() { |
| 116 |
do_action( 'jet-form-builder/use-form/register-assets' ); |
| 117 |
|
| 118 |
$script_asset = require_once $this->get_dir( 'assets/build/editor.package.asset.php' ); |
| 119 |
|
| 120 |
array_push( |
| 121 |
$script_asset['dependencies'], |
| 122 |
$this->get_handle( 'use-form' ), |
| 123 |
'jet-fb-components' |
| 124 |
); |
| 125 |
|
| 126 |
wp_enqueue_script( |
| 127 |
$this->get_handle( 'package' ), |
| 128 |
$this->get_url( 'assets/build/editor.package.js' ), |
| 129 |
$script_asset['dependencies'], |
| 130 |
$script_asset['version'], |
| 131 |
true |
| 132 |
); |
| 133 |
} |
| 134 |
|
| 135 |
public function enqueue_frontend_assets() { |
| 136 |
do_action( 'jet-form-builder/use-form/register-assets' ); |
| 137 |
|
| 138 |
$script_asset = require_once $this->get_dir( 'assets/build/preview.frontend.asset.php' ); |
| 139 |
|
| 140 |
array_push( |
| 141 |
$script_asset['dependencies'], |
| 142 |
$this->get_handle( 'use-form' ), |
| 143 |
'jet-plugins' |
| 144 |
); |
| 145 |
|
| 146 |
wp_enqueue_style( 'wp-components' ); |
| 147 |
wp_enqueue_style( 'jet-fb-components' ); |
| 148 |
|
| 149 |
wp_enqueue_script( |
| 150 |
$this->get_handle( 'preview-frontend' ), |
| 151 |
$this->get_url( 'assets/build/preview.frontend.js' ), |
| 152 |
$script_asset['dependencies'], |
| 153 |
$script_asset['version'], |
| 154 |
true |
| 155 |
); |
| 156 |
} |
| 157 |
|
| 158 |
public function add_default_fields_to_form( $arguments ) { |
| 159 |
$arguments['template'] = array( |
| 160 |
array( Block_Helper::pref( 'welcome' ) ), |
| 161 |
); |
| 162 |
|
| 163 |
return $arguments; |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* @return Preview |
| 168 |
*/ |
| 169 |
public function get_preview(): Preview { |
| 170 |
return $this->preview; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* @return Use_Form |
| 175 |
*/ |
| 176 |
public function get_use_form(): Use_Form { |
| 177 |
return $this->use_form; |
| 178 |
} |
| 179 |
} |
| 180 |
|