PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.6
JetFormBuilder — Dynamic Blocks Form Builder v2.1.6
3.6.5.2 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 All 130 releases
jetformbuilder / includes / compatibility / jet-engine / generators / get-from-field.php
get-from-field.php
75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Jet_Form_Builder\Compatibility\Jet_Engine\Generators;
4
5 use Jet_Form_Builder\Generators\Base;
6
7 class Get_From_Field extends Base {
8
9 /**
10 * Returns generator ID
11 *
12 * @return string
13 */
14 public function get_id() {
15 return 'get_from_field';
16 }
17
18 /**
19 * Returns generator name
20 *
21 * @return string
22 */
23 public function get_name() {
24 return __( 'Get values list from JetEngine field options', 'jet-form-builder' );
25 }
26
27 /**
28 * Returns generated options list
29 *
30 * @param $args
31 *
32 * @return array
33 */
34 public function generate( $args ) {
35 $field = $args['generator_field'] ?? '';
36 $all_fields = jet_engine()->meta_boxes->get_registered_fields();
37 $found_field = null;
38 $result = array();
39 $parse_field = explode( '|', $field );
40 $field = $parse_field[0];
41 $sub_field = isset( $parse_field[1] ) ? $parse_field[1] : false;
42
43 foreach ( $all_fields as $object => $fields ) {
44 foreach ( $fields as $field_data ) {
45 if ( ! empty( $field_data['name'] ) && $field === $field_data['name'] ) {
46 $found_field = $field_data;
47 }
48 }
49 }
50
51 if ( ! empty( $sub_field ) && ! empty( $found_field['repeater-fields'] ) ) {
52 foreach ( $found_field['repeater-fields'] as $repeater_field_data ) {
53 if ( ! empty( $repeater_field_data['name'] ) && $sub_field === $repeater_field_data['name'] ) {
54 $found_field = $repeater_field_data;
55 }
56 }
57 }
58
59 if ( empty( $found_field['options'] ) ) {
60 return $result;
61 }
62
63 foreach ( $found_field['options'] as $option ) {
64 $result[] = array(
65 'value' => $option['key'],
66 'label' => $option['value'],
67 );
68 }
69
70 return $result;
71
72 }
73
74 }
75