PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.23.0
GiveWP – Donation Plugin and Fundraising Platform v2.23.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 in GiveWP – Donation Plugin and Fundraising Platform 2.23.0, at src/FormAPI/Form/Group.php

98 lines 2.0 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 /**
10 * Field options.
11 * Note: Allow to update repeater aka group field frontend output.
12 *
13 * @since 2.7.0
14 * @var array
15 */
16 public $options = [];
17
18 /**
19 * Sub fields
20 *
21 * Note: Allow developer to add sub fields to group.
22 *
23 * @since 2.7.0
24 * @var array
25 */
26 public $fields = [];
27
28 /**
29 * @inheritDoc
30 */
31 public function parse($array)
32 {
33 parent::parse($array);
34
35 $defaultOptions = [
36 'header_title' => esc_attr__('Group', 'give'),
37 'add_button' => esc_html__('Add Row', 'give'),
38 'group_numbering' => 0,
39 'close_tabs' => 0,
40 ];
41
42 $this->options = isset($array['options']) ?
43 array_merge($defaultOptions, $array['options']) :
44 $defaultOptions;
45
46 $this->fields = isset($array['fields']) ?
47 $array['fields'] :
48 [];
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function toArray()
55 {
56 return array_merge(
57 parent::toArray(),
58 [
59 'options' => $this->options,
60 'fields' => $this->fields,
61 ]
62 );
63 }
64
65 /**
66 * Get sub fields.
67 *
68 * @since 2.7.0
69 *
70 * @param string $fieldId
71 *
72 * @return array
73 */
74 public function getFieldArguments($fieldId)
75 {
76 $field = current(
77 array_filter(
78 $this->fields,
79 static function ($field) use ($fieldId) {
80 return $fieldId === $field['id'];
81 }
82 )
83 );
84
85 // Validate field.
86 if ( ! $field) {
87 throw new InvalidArgumentException(
88 sprintf(
89 __('Field with %1$s Id does not exist in group.', 'give'),
90 $fieldId
91 )
92 );
93 }
94
95 return $field;
96 }
97 }
98