8889841cSection.php000064400000003103150446574420006671 0ustar00validate($array); $group->id = $array['id']; $group->name = $array['name']; $group->desc = isset($array['desc']) ? $array['desc'] : null; foreach ($array['fields'] as $field) { $group->fields[] = Fields::fromArray($field); } return $group; } /** * Validate group arguments * * @since 2.7.0 * * @param $array */ private function validate($array) { $required = ['id', 'name', 'fields']; if (array_diff($required, array_keys($array))) { throw new InvalidArgumentException( __('To create a Group object, please provide id, name and fields.', 'give') ); } } } Fields.php000064400000005136150446574420006503 0ustar00 Text::class, 'textarea' => Textarea::class, 'file' => File::class, 'media' => Media::class, 'radio' => Radio::class, 'wysiwyg' => Wysiwyg::class, 'colorpicker' => Colorpicker::class, 'group' => Group::class, 'select' => Select::class, ]; /** * Get field object. * * @since 2.7.0 * * @param array $array * * @return Form\Field */ public static function fromArray($array) { $field = new static(); $field->validate($array); /** * Filter the field classes * * @since 2.7.0 * * @param Form\Field[] $fieldClasses */ $field->fieldClasses = apply_filters('give_form_api_field_classes', $field->fieldClasses); /* @var Form\Field $fieldClass */ $fieldClass = $field->fieldClasses[$field->getFieldType($array['type'])]; return $fieldClass::fromArray($array); } /** * Get field class name. * Note: * 1. Field name create with {fieldType_modifier} logic. Use underscore in field type only if you want to add a modifier. For example: text_small, radio_inline etc. * 2. This function exist for backward compatibility and can be remove in future * * @since 2.7.0 * * @param $type * * @return string */ private function getFieldType($type) { if (false !== strpos($type, '_')) { $type = current(explode('_', $type, 2)); } return $type; } /** * Validate field arguments * * @since 2.7.0 * * @param array $array * * @throws InvalidArgumentException */ private function validate($array) { $required = ['id', 'name', 'type']; $array = array_filter($array); // Remove empty values. if (array_diff($required, array_keys($array))) { throw new InvalidArgumentException( __('To create a Field object, please provide valid id, name and type.', 'give') ); } } } Form/Radio.php000064400000001516150446574420007234 0ustar00options = isset($array['options']) ? $array['options'] : []; $type = explode('_', $this->type, 2); $this->displayStyle = false !== strpos('_', $this->type) ? array_pop($type) : ''; } /** * @inheritDoc */ public function toArray() { return array_merge( parent::toArray(), [ 'options' => $this->options, ] ); } } Form/Group.php000064400000004013150446574420007265 0ustar00 esc_attr__('Group', 'give'), 'add_button' => esc_html__('Add Row', 'give'), 'group_numbering' => 0, 'close_tabs' => 0, ]; $this->options = isset($array['options']) ? array_merge($defaultOptions, $array['options']) : $defaultOptions; $this->fields = isset($array['fields']) ? $array['fields'] : []; } /** * @inheritDoc */ public function toArray() { return array_merge( parent::toArray(), [ 'options' => $this->options, 'fields' => $this->fields, ] ); } /** * Get sub fields. * * @since 2.7.0 * * @param string $fieldId * * @return array */ public function getFieldArguments($fieldId) { $field = current( array_filter( $this->fields, static function ($field) use ($fieldId) { return $fieldId === $field['id']; } ) ); // Validate field. if ( ! $field) { throw new InvalidArgumentException( sprintf( __('Field with %1$s Id does not exist in group.', 'give'), $fieldId ) ); } return $field; } } Form/Text.php000064400000002604150446574420007121 0ustar00beforeField = isset($array['before_field']) ? $array['before_field'] : ''; $this->afterField = isset($array['after_field']) ? $array['after_field'] : ''; $this->dataType = isset($array['data_type']) ? $array['data_type'] : ''; $type = explode('_', $this->type, 2); $this->size = false !== strpos('_', $this->type) ? array_pop($type) : ''; } /** * @inheritDoc */ public function toArray() { return array_merge( parent::toArray(), [ 'before_field' => $this->beforeField, 'after_field' => $this->afterField, ] ); } } Form/Textarea.php000064400000000106150446574420007745 0ustar00fieldValueType = isset($array['fvalue']) ? $array['fvalue'] : 'url'; } /** * @inheritDoc */ public function toArray() { return array_merge( parent::toArray(), [ 'fvalue' => $this->fieldValueType, ] ); } } Form/Field.php000064400000006267150446574420007231 0ustar00id = $array['id']; $this->name = $array['name']; $this->type = $array['type']; $this->desc = isset($array['desc']) ? $array['desc'] : ''; $this->style = isset($array['style']) ? $array['style'] : ''; $this->wrapperClass = isset($array['wrapper_class']) ? $array['wrapper_class'] : ''; $this->defaultValue = isset($array['default']) ? $array['default'] : null; $this->value = isset($array['value']) ? $array['value'] : null; $this->attributes = isset($array['attributes']) ? $array['attributes'] : []; } /** * Get Field object. * * @since 2.7.0 * * @param array $array * * @return static */ public static function fromArray($array) { $field = new static(); $field->validate($array); $field->parse($array); return $field; } /** * Validate field arguments * * @since 2.7.0 * * @param $array */ public function validate($array) { $required = ['id', 'name', 'type']; $array = array_filter($array); // Remove empty values. if (array_diff($required, array_keys($array))) { throw new InvalidArgumentException( __('To create a TextField object, please provide valid id, name and type.', 'give') ); } } /** * Convert field object to array. * * @since 2.7.0 * @return array */ public function toArray() { return [ 'id' => $this->id, 'name' => $this->name, 'type' => $this->type, 'desc' => $this->desc, 'style' => $this->style, 'wrapper_class' => $this->wrapperClass, 'value' => $this->value, 'default' => $this->defaultValue, 'attributes' => $this->attributes, ]; } } Form/File.php000064400000000102150446574420007043 0ustar00options = isset($array[ 'options' ]) ? $array[ 'options' ] : []; } /** * @inheritDoc */ public function toArray() { return array_merge( parent::toArray(), [ 'options' => $this->options, ] ); } } Form/Wysiwyg.php000064400000000105150446574420007651 0ustar00