PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / FormAPI / Form / Group.php
Group.php
93 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\FormAPI\Form;
4
5 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
6
7 class Group extends Field {
8 /**
9 * Field options.
10 * Note: Allow to update repeater aka group field frontend output.
11 *
12 * @since 2.7.0
13 * @var array
14 */
15 public $options = [];
16
17 /**
18 * Sub fields
19 *
20 * Note: Allow developer to add sub fields to group.
21 *
22 * @since 2.7.0
23 * @var array
24 */
25 public $fields = [];
26
27 /**
28 * @inheritDoc
29 */
30 public function parse( $array ) {
31 parent::parse( $array );
32
33 $defaultOptions = [
34 'header_title' => esc_attr__( 'Group', 'give' ),
35 'add_button' => esc_html__( 'Add Row', 'give' ),
36 'group_numbering' => 0,
37 'close_tabs' => 0,
38 ];
39
40 $this->options = isset( $array['options'] ) ?
41 array_merge( $defaultOptions, $array['options'] ) :
42 $defaultOptions;
43
44 $this->fields = isset( $array['fields'] ) ?
45 $array['fields'] :
46 [];
47 }
48
49 /**
50 * @inheritDoc
51 */
52 public function toArray() {
53 return array_merge(
54 parent::toArray(),
55 [
56 'options' => $this->options,
57 'fields' => $this->fields,
58 ]
59 );
60 }
61
62
63 /**
64 * Get sub fields.
65 *
66 * @since 2.7.0
67 * @param string $fieldId
68 * @return array
69 */
70 public function getFieldArguments( $fieldId ) {
71 $field = current(
72 array_filter(
73 $this->fields,
74 static function( $field ) use ( $fieldId ) {
75 return $fieldId === $field['id'];
76 }
77 )
78 );
79
80 // Validate field.
81 if ( ! $field ) {
82 throw new InvalidArgumentException(
83 sprintf(
84 __( 'Field with %1$s Id does not exist in group.', 'give' ),
85 $fieldId
86 )
87 );
88 }
89
90 return $field;
91 }
92 }
93