PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.2
JetFormBuilder — Dynamic Blocks Form Builder v3.4.2
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 / compatibility / jet-engine / preset-sources / preset-source-options-page.php
jetformbuilder / compatibility / jet-engine / preset-sources Last commit date
preset-source-options-page.php 2 years ago preset-user.php 2 years ago
preset-source-options-page.php
139 lines
1 <?php
2
3
4 namespace JFB_Compatibility\Jet_Engine\Preset_Sources;
5
6 use Jet_Form_Builder\Classes\Tools;
7 use Jet_Form_Builder\Exceptions\Preset_Exception;
8 use Jet_Form_Builder\Presets\Sources\Base_Source;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 class Preset_Source_Options_Page extends Base_Source {
16
17 private $page = '';
18
19 public function get_id() {
20 return 'option_page';
21 }
22
23 /**
24 * @return object
25 * @throws Preset_Exception
26 */
27 public function query_source() {
28 if ( empty( $this->page ) ) {
29 throw new Preset_Exception( 'Empty page' );
30 }
31
32 $item = jet_engine()->options_pages->registered_pages[ $this->page ] ?? false;
33
34 if ( ! $item ) {
35 throw new Preset_Exception(
36 sprintf(
37 'Undefined option page: %s',
38 esc_html( $this->page )
39 )
40 );
41 }
42
43 return $item;
44 }
45
46 /**
47 * @return string
48 * @throws Preset_Exception
49 */
50 protected function get_prop() {
51 $prop = explode( '::', parent::get_prop() );
52
53 $this->page = $prop[0] ?? '';
54 $slug = $prop[1] ?? '';
55
56 if ( empty( $this->page ) || empty( $slug ) ) {
57 throw new Preset_Exception( 'Undefined option' );
58 }
59
60 return $slug;
61 }
62
63 /**
64 * @param string $prop
65 *
66 * @return string
67 *
68 * @throws Preset_Exception
69 * @see https://gist.github.com/MjHead/49ebe7ecc20bff9aaf8516417ed27c38
70 */
71 public function default_prop( string $prop ) {
72 if ( ! is_a( $this->src(), '\Jet_Engine_Options_Page_Factory' ) ) {
73 throw new Preset_Exception( 'Source is not instance of ' . \Jet_Engine_Options_Page_Factory::class );
74 }
75
76 return $this->src()->get( $prop );
77 }
78
79 protected function before_query_extra_field( $field ) {
80 $this->prop = $field;
81 }
82
83 public function after_register() {
84 add_filter( 'jet-form-builder/editor/preset-config', array( $this, 'manage_config' ) );
85 }
86
87 public function manage_config( $config ) {
88 $config['global_fields'][0]['options'][] = array(
89 'value' => $this->get_id(),
90 'label' => __( 'Option Page', 'jet-form-builder' ),
91 );
92
93 $config['map_fields'][] = array(
94 'name' => 'prop',
95 'label' => __( 'Option Value', 'jet-form-builder' ),
96 'type' => 'grouped_select',
97 'options' => Tools::with_placeholder(
98 $this->get_options_fields_for_select()
99 ),
100 'parent_condition' => array(
101 'field' => 'from',
102 'value' => $this->get_id(),
103 ),
104 );
105
106 return $config;
107 }
108
109 public function get_options_fields_for_select(): array {
110 $result = array();
111
112 foreach ( jet_engine()->options_pages->options_list as $slug => $data ) {
113 $blocks_group = array();
114
115 foreach ( $data['options'] as $name => $field_data ) {
116 $black_list = array( 'html', 'tab', 'accordion', 'endpoint' );
117
118 if ( ! in_array( $field_data['type'], $black_list, true ) ) {
119 $group[ $name ] = $field_data['title'];
120
121 $blocks_group[] = array(
122 'value' => $name,
123 'label' => $field_data['title'],
124 );
125 }
126 }
127 if ( ! empty( $blocks_group ) ) {
128 $result[] = array(
129 'label' => $data['label'],
130 'values' => $blocks_group,
131 );
132 }
133 }
134
135 return $result;
136 }
137
138 }
139