PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.0.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.0.1
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 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 All 134 releases
jetformbuilder / modules / block-parsers / fields / repeater-field-parser.php

repeater-field-parser.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.0.1, at modules/block-parsers/fields/repeater-field-parser.php

68 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace JFB_Modules\Block_Parsers\Fields;
5
6 use Jet_Form_Builder\Request\Exceptions\Sanitize_Value_Exception;
7 use JFB_Modules\Block_Parsers\Field_Data_Parser;
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 class Repeater_Field_Parser extends Field_Data_Parser {
15
16 public function type() {
17 return 'repeater-field';
18 }
19
20 /**
21 * @return int|void
22 * @throws Sanitize_Value_Exception
23 */
24 public function get_response() {
25 $indexes = $this->get_indexes();
26
27 if ( ! $indexes ) {
28 return '';
29 }
30
31 if ( ! $this->get_inner_template() ) {
32 return -1;
33 }
34
35 foreach ( $indexes as $index ) {
36 $context = clone $this->get_inner_template();
37 $context->set_index_in_parent( $this->add_inner( $context ) );
38
39 $context->set_request( $this->value[ $index ] ?? array() )
40 ->set_files( $this->file[ $index ] ?? array() );
41
42 $context->apply();
43 }
44
45 $this->set_file( false );
46
47 return count( $indexes );
48 }
49
50 protected function get_indexes(): array {
51 if ( ! is_array( $this->value ) ) {
52 $this->value = array();
53 }
54 if ( ! is_array( $this->file ) ) {
55 $this->file = array();
56 }
57
58 $indexes = array_keys( $this->value );
59 $file_indexes = array_keys( $this->file );
60
61 /**
62 * @see https://github.com/Crocoblock/issues-tracker/issues/2095
63 */
64 return max( $indexes, $file_indexes );
65 }
66
67 }
68