date-field-parser.php
3 years ago
datetime-field-parser.php
3 years ago
datetime-trait.php
3 years ago
hidden-field-parser.php
3 years ago
media-field-parser.php
3 years ago
repeater-field-parser.php
3 years ago
text-field-parser.php
3 years ago
wysiwyg-field-parser.php
3 years ago
repeater-field-parser.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Request\Fields; |
| 5 | |
| 6 | use Jet_Form_Builder\Plugin; |
| 7 | use Jet_Form_Builder\Request\Field_Data_Parser; |
| 8 | use Jet_Form_Builder\Request\Parser_Manager; |
| 9 | |
| 10 | class Repeater_Field_Parser extends Field_Data_Parser { |
| 11 | |
| 12 | public function type() { |
| 13 | return 'repeater-field'; |
| 14 | } |
| 15 | |
| 16 | public function get_response() { |
| 17 | $response = array(); |
| 18 | $indexes = $this->get_indexes(); |
| 19 | $context = clone $this->context; |
| 20 | |
| 21 | foreach ( $indexes as $index ) { |
| 22 | $row = $this->value[ $index ] ?? array(); |
| 23 | $files = $this->file[ $index ] ?? array(); |
| 24 | |
| 25 | $context->set_request_context( $row )->set_files_context( $files ); |
| 26 | |
| 27 | $response[ $index ] = Parser_Manager::instance()->get_values_fields( $this->inner, $context ); |
| 28 | } |
| 29 | |
| 30 | return $response; |
| 31 | } |
| 32 | |
| 33 | protected function get_indexes(): array { |
| 34 | if ( ! is_array( $this->value ) ) { |
| 35 | $this->value = array(); |
| 36 | } |
| 37 | if ( ! is_array( $this->file ) ) { |
| 38 | $this->file = array(); |
| 39 | } |
| 40 | |
| 41 | $indexes = array_keys( $this->value ); |
| 42 | $file_indexes = array_keys( $this->file ); |
| 43 | |
| 44 | /** |
| 45 | * @see https://github.com/Crocoblock/issues-tracker/issues/2095 |
| 46 | */ |
| 47 | return max( $indexes, $file_indexes ); |
| 48 | } |
| 49 | |
| 50 | } |
| 51 |