| @@ -3,95 +3,90 @@ | ||
| 3 | 3 | namespace Give\FormAPI\Form; |
| 4 | 4 | |
| 5 | 5 | use Give\Framework\Exceptions\Primitives\InvalidArgumentException; |
| 6 | 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 = []; | |
| 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 = []; | |
| 17 | 16 | |
| 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 = []; | |
| 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 = []; | |
| 27 | 26 | |
| 28 | - /** | |
| 29 | - * @inheritDoc | |
| 30 | - */ | |
| 31 | - public function parse($array) | |
| 32 | - { | |
| 33 | - parent::parse($array); | |
| 27 | + /** | |
| 28 | + * @inheritDoc | |
| 29 | + */ | |
| 30 | + public function parse( $array ) { | |
| 31 | + parent::parse( $array ); | |
| 34 | 32 | |
| 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 | - ]; | |
| 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 | + ]; | |
| 41 | 39 | |
| 42 | - $this->options = isset($array['options']) ? | |
| 43 | - array_merge($defaultOptions, $array['options']) : | |
| 44 | - $defaultOptions; | |
| 40 | + $this->options = isset( $array['options'] ) ? | |
| 41 | + array_merge( $defaultOptions, $array['options'] ) : | |
| 42 | + $defaultOptions; | |
| 45 | 43 | |
| 46 | - $this->fields = isset($array['fields']) ? | |
| 47 | - $array['fields'] : | |
| 48 | - []; | |
| 49 | - } | |
| 44 | + $this->fields = isset( $array['fields'] ) ? | |
| 45 | + $array['fields'] : | |
| 46 | + []; | |
| 47 | + } | |
| 50 | 48 | |
| 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 | - } | |
| 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 | + } | |
| 64 | 61 | |
| 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 | 62 | |
| 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 | - } | |
| 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 | + ); | |
| 94 | 79 | |
| 95 | - return $field; | |
| 96 | - } | |
| 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 | + } | |
| 97 | 92 | } |