je-query-object-handlers
3 years ago
base.php
3 years ago
get-from-db.php
3 years ago
get-from-field.php
3 years ago
get-from-je-query.php
3 years ago
num-range-manual.php
3 years ago
num-range.php
3 years ago
get-from-field.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Jet_Form_Builder\Generators; |
| 4 | |
| 5 | class Get_From_Field extends Base { |
| 6 | |
| 7 | /** |
| 8 | * Returns generator ID |
| 9 | * |
| 10 | * @return string |
| 11 | */ |
| 12 | public function get_id() { |
| 13 | return 'get_from_field'; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Returns generator name |
| 18 | * |
| 19 | * @return string |
| 20 | */ |
| 21 | public function get_name() { |
| 22 | return __( 'Get values list from JetEngine field options', 'jet-form-builder' ); |
| 23 | } |
| 24 | |
| 25 | public function can_generate() { |
| 26 | return function_exists( 'jet_engine' ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Returns generated options list |
| 31 | * |
| 32 | * @param $args |
| 33 | * |
| 34 | * @return array |
| 35 | */ |
| 36 | public function generate( $args ) { |
| 37 | $field = $args['generator_field'] ?? ''; |
| 38 | $all_fields = jet_engine()->meta_boxes->get_registered_fields(); |
| 39 | $found_field = null; |
| 40 | $result = array(); |
| 41 | $parse_field = explode( '|', $field ); |
| 42 | $field = $parse_field[0]; |
| 43 | $sub_field = isset( $parse_field[1] ) ? $parse_field[1] : false; |
| 44 | |
| 45 | foreach ( $all_fields as $object => $fields ) { |
| 46 | foreach ( $fields as $field_data ) { |
| 47 | if ( ! empty( $field_data['name'] ) && $field === $field_data['name'] ) { |
| 48 | $found_field = $field_data; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if ( ! empty( $sub_field ) && ! empty( $found_field['repeater-fields'] ) ) { |
| 54 | foreach ( $found_field['repeater-fields'] as $repeater_field_data ) { |
| 55 | if ( ! empty( $repeater_field_data['name'] ) && $sub_field === $repeater_field_data['name'] ) { |
| 56 | $found_field = $repeater_field_data; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if ( empty( $found_field['options'] ) ) { |
| 62 | return $result; |
| 63 | } |
| 64 | |
| 65 | foreach ( $found_field['options'] as $option ) { |
| 66 | $result[] = array( |
| 67 | 'value' => $option['key'], |
| 68 | 'label' => $option['value'], |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | return $result; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | } |
| 77 |