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