PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / form-record / module.php
jetformbuilder / modules / form-record Last commit date
action-types 2 years ago admin 2 years ago assets 1 year ago constraints 2 years ago export 2 years ago models 2 years ago query-views 1 year ago rest-endpoints 1 year ago controller.php 1 year ago module.php 1 year ago records-rest-controller.php 2 years ago tools.php 2 years ago
module.php
258 lines
1 <?php
2
3
4 namespace JFB_Modules\Form_Record;
5
6 use Jet_Form_Builder\Actions\Manager;
7 use Jet_Form_Builder\Admin\Single_Pages\Base_Single_Page;
8 use Jet_Form_Builder\Admin\Single_Pages\Meta_Containers\Base_Meta_Container;
9 use Jet_Form_Builder\Admin\Single_Pages\Meta_Containers\Side_Meta_Container;
10 use Jet_Form_Builder\Classes\Post\Post_Tools;
11 use Jet_Form_Builder\Exceptions\Handler_Exception;
12 use Jet_Form_Builder\Exceptions\Query_Builder_Exception;
13 use Jet_Form_Builder\Exceptions\Repository_Exception;
14 use JFB_Components\Admin\Print_Page\Header;
15 use JFB_Modules\Form_Record\Admin\Meta_Boxes\Form_Record_Print_Values_Box;
16 use JFB_Modules\Form_Record\Admin\Pages\Export_Page;
17 use JFB_Modules\Form_Record\Admin\Pages\Print_Page;
18 use JFB_Modules\Form_Record\Admin\Pages\Single_Form_Record_Print_Page;
19 use JFB_Modules\Form_Record\Query_Views\Record_View;
20 use JFB_Modules\Gateways\Scenarios_Abstract\Scenario_Logic_Base;
21 use JFB_Components\Module\Base_Module_After_Install_It;
22 use JFB_Components\Module\Base_Module_Dir_It;
23 use JFB_Components\Module\Base_Module_Dir_Trait;
24 use JFB_Components\Module\Base_Module_Handle_It;
25 use JFB_Components\Module\Base_Module_Handle_Trait;
26 use JFB_Components\Module\Base_Module_It;
27 use JFB_Components\Module\Base_Module_Url_It;
28 use JFB_Components\Module\Base_Module_Url_Trait;
29 use JFB_Modules\Form_Record\Action_Types\Save_Record;
30 use JFB_Modules\Form_Record\Admin\Meta_Boxes\Record_To_Payment_Box;
31 use JFB_Modules\Form_Record\Admin\Pages\Form_Records;
32 use JFB_Modules\Form_Record\Admin\Pages\Single_Form_Record_Page;
33 use JFB_Modules\Dev;
34
35 // If this file is called directly, abort.
36 if ( ! defined( 'WPINC' ) ) {
37 die;
38 }
39
40 final class Module implements
41 Base_Module_It,
42 Base_Module_Url_It,
43 Base_Module_Dir_It,
44 Base_Module_After_Install_It,
45 Base_Module_Handle_It {
46
47 use Base_Module_Handle_Trait;
48 use Base_Module_Url_Trait;
49 use Base_Module_Dir_Trait;
50
51 private $rest;
52
53 public function rep_item_id() {
54 return 'form-record';
55 }
56
57 public function condition(): bool {
58 return true;
59 }
60
61 public function on_install() {
62 $this->rest = new Records_Rest_Controller();
63 }
64
65 public function on_uninstall() {
66 unset( $this->rest );
67 }
68
69 public function init_hooks() {
70 // actions
71 add_action(
72 'rest_api_init',
73 array( $this->get_rest(), 'register_routes' )
74 );
75 add_action(
76 'jet-form-builder/actions/register',
77 array( $this, 'register_actions' )
78 );
79 add_action(
80 'jet-form-builder/gateways/before-send',
81 array( $this, 'before_send_gateway' ),
82 10,
83 3
84 );
85 add_action(
86 'jet-form-builder/before-print-page/header',
87 array( $this, 'before_print_page' ),
88 10,
89 2
90 );
91
92 // filters
93 add_filter(
94 'jet-form-builder/admin/pages',
95 array( $this, 'add_admin_pages' )
96 );
97 add_filter(
98 'jet-form-builder/admin/single-pages',
99 array( $this, 'add_single_admin_pages' )
100 );
101 add_filter(
102 'jet-form-builder/page-containers/jfb-payments-single',
103 array( $this, 'add_box_to_single_payment' )
104 );
105 add_filter(
106 'jet-form-builder/admin/action-pages',
107 array( $this, 'add_action_admin_pages' )
108 );
109 add_action(
110 'jet-form-builder/editor-assets/before',
111 array( $this, 'editor_assets' ),
112 0
113 );
114 }
115
116 public function remove_hooks() {
117 // actions
118 remove_action(
119 'rest_api_init',
120 array( $this->get_rest(), 'register_routes' )
121 );
122 remove_action(
123 'jet-form-builder/actions/register',
124 array( $this, 'register_actions' )
125 );
126 remove_action(
127 'jet-form-builder/gateways/before-send',
128 array( $this, 'before_send_gateway' )
129 );
130 remove_action(
131 'jet-form-builder/before-print-page/header',
132 array( $this, 'before_print_page' )
133 );
134
135 // filters
136 remove_filter(
137 'jet-form-builder/admin/pages',
138 array( $this, 'add_admin_pages' )
139 );
140 remove_filter(
141 'jet-form-builder/admin/single-pages',
142 array( $this, 'add_single_admin_pages' )
143 );
144 remove_filter(
145 'jet-form-builder/page-containers/jfb-payments-single',
146 array( $this, 'add_box_to_single_payment' )
147 );
148 remove_filter(
149 'jet-form-builder/admin/action-pages',
150 array( $this, 'add_action_admin_pages' )
151 );
152 remove_action(
153 'jet-form-builder/editor-assets/before',
154 array( $this, 'editor_assets' ),
155 0
156 );
157 }
158
159 public function register_actions( Manager $manager ) {
160 $manager->register_action_type( new Save_Record() );
161 }
162
163 public function add_admin_pages( array $pages ): array {
164 $pages[] = new Form_Records();
165
166 return $pages;
167 }
168
169 public function add_single_admin_pages( array $pages ): array {
170 $pages[] = new Single_Form_Record_Page();
171
172 return $pages;
173 }
174
175 public function add_action_admin_pages( array $pages ): array {
176 array_push(
177 $pages,
178 new Export_Page(),
179 new Print_Page()
180 );
181
182 return $pages;
183 }
184
185 /**
186 * @param Header $header
187 * @param Base_Single_Page $page
188 */
189 public function before_print_page( Header $header, Base_Single_Page $page ) {
190 if ( ! ( $page instanceof Single_Form_Record_Print_Page ) ) {
191 return;
192 }
193
194 try {
195 $record = Record_View::findById( $page->get_id() );
196 } catch ( Query_Builder_Exception $exception ) {
197 return;
198 }
199
200 $form_title = Post_Tools::get_title( $record['form_id'] );
201
202 $header->set_title(
203 sprintf(
204 /* translators: %s - form title */
205 __( '%s ‹ JetFormBuilder Record', 'jet-form-builder' ),
206 $form_title
207 )
208 );
209 }
210
211 /**
212 * @param Base_Meta_Container[] $containers
213 *
214 * @return array
215 */
216 public function add_box_to_single_payment( array $containers ): array {
217 $containers[1]->add_meta_box( new Record_To_Payment_Box() );
218
219 return $containers;
220 }
221
222 public function before_send_gateway( $status, $action_error, Scenario_Logic_Base $scenario ) {
223 // prepare record controller, for saving errors & actions
224 $record = $scenario->get_scenario_row( 'record' );
225 $controller = ( new Controller() )->set_record_id( $record['id'] );
226 $controller->set_setting(
227 'save_errors',
228 jet_form_builder()->has_module( Dev\Module::class )
229 );
230
231 try {
232 $controller->save_fields();
233 $controller->save_actions();
234 $controller->save_errors();
235
236 } catch ( Handler_Exception $exception ) {
237 // do nothing
238 }
239 }
240
241 public function editor_assets() {
242 $script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' );
243
244 wp_enqueue_script(
245 $this->get_handle(),
246 $this->get_url( 'assets/build/editor.js' ),
247 $script_asset['dependencies'],
248 $script_asset['version'],
249 true
250 );
251 }
252
253 public function get_rest(): Records_Rest_Controller {
254 return $this->rest;
255 }
256
257 }
258