PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Payments / Components / ItemQuantity.php

ItemQuantity.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.14, at app/Modules/Payments/Components/ItemQuantity.php

149 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Payments\Components;
4
5 if (!defined('ABSPATH')) {
6 exit; // Exit if accessed directly.
7 }
8
9 use FluentForm\App\Helpers\Helper;
10 use FluentForm\App\Services\FormBuilder\BaseFieldManager;
11 use FluentForm\App\Services\FormBuilder\Components\Text;
12 use FluentForm\Framework\Helpers\ArrayHelper;
13
14 class ItemQuantity extends BaseFieldManager
15 {
16 public function __construct(
17 $key = 'item_quantity_component',
18 $title = 'Quantity',
19 $tags = ['custom', 'payment', 'quantity'],
20 $position = 'payments'
21 )
22 {
23 parent::__construct(
24 $key,
25 $title,
26 $tags,
27 $position
28 );
29 }
30
31 function getComponent()
32 {
33 return array(
34 'index' => 6,
35 'element' => $this->key,
36 'attributes' => array(
37 'type' => 'number',
38 'name' => 'item-quantity',
39 'value' => '',
40 'id' => '',
41 'class' => '',
42 'placeholder' => '',
43 'data-quantity_item' => 'yes'
44 ),
45 'settings' => array(
46 'container_class' => '',
47 'is_payment_field' => 'yes',
48 'label' => __('Quantity', 'fluentform'),
49 'admin_field_label' => '',
50 'label_placement' => '',
51 'help_message' => '',
52 'number_step' => '',
53 'prefix_label' => '',
54 'suffix_label' => '',
55 'target_product' => '',
56 'validation_rules' => array(
57 'required' => array(
58 'value' => false,
59 'global' => true,
60 'message' => Helper::getGlobalDefaultMessage('required'),
61 'global_message' => Helper::getGlobalDefaultMessage('required'),
62 ),
63 'numeric' => array(
64 'value' => true,
65 'global' => true,
66 'message' => Helper::getGlobalDefaultMessage('numeric'),
67 'global_message' => Helper::getGlobalDefaultMessage('numeric'),
68 ),
69 'min' => array(
70 'value' => '',
71 'global' => true,
72 'message' => Helper::getGlobalDefaultMessage('min'),
73 'global_message' => Helper::getGlobalDefaultMessage('min'),
74 ),
75 'max' => array(
76 'value' => '',
77 'global' => true,
78 'message' => Helper::getGlobalDefaultMessage('max'),
79 'global_message' => Helper::getGlobalDefaultMessage('max'),
80 ),
81 ),
82 'conditional_logics' => array()
83 ),
84 'editor_options' => array(
85 'title' => __('Item Quantity', 'fluentform'),
86 'icon_class' => 'ff-edit-keyboard-o',
87 'template' => 'inputText'
88 ),
89 );
90 }
91
92 public function getGeneralEditorElements()
93 {
94 return [
95 'label',
96 'label_placement',
97 'admin_field_label',
98 'placeholder',
99 'target_product',
100 'validation_rules'
101 ];
102 }
103
104 public function getAdvancedEditorElements()
105 {
106 return [
107 'value',
108 'container_class',
109 'class',
110 'help_message',
111 'number_step',
112 'prefix_label',
113 'suffix_label',
114 'name',
115 'conditional_logics',
116 'calculation_settings'
117 ];
118 }
119
120 public function getEditorCustomizationSettings()
121 {
122 return [
123 'target_product' => array(
124 'template' => 'targetProduct',
125 'label' => __('Product Field Mapping', 'fluentform'),
126 'help_text' => __('Select which Product this field is tied to', 'fluentform'),
127 )
128 ];
129 }
130
131 function render($data, $form)
132 {
133 $data['attributes']['class'] .= ' ff_quantity_item';
134 $data['attributes']['data-target_product'] = ArrayHelper::get($data, 'settings.target_product');
135
136 if (ArrayHelper::get($data, 'settings.validation_rules.min.value') == '') {
137 ArrayHelper::set($data, 'settings.validation_rules.min.value', 0);
138 }
139
140 ArrayHelper::set($data, 'attributes.min', ArrayHelper::get($data, 'settings.validation_rules.min.value'));
141
142 if (ArrayHelper::get($data, 'settings.validation_rules.max.value')) {
143 ArrayHelper::set($data, 'attributes.max', ArrayHelper::get($data, 'settings.validation_rules.max.value'));
144 }
145
146 return (new Text())->compile($data, $form);
147 }
148 }
149