@@ -127,16 +127,25 @@ public static function getMiscDisclaimer(string $type = ''): array
127
127
/**
128
128
* Get settings input field with global variable.
129
129
*
130
- * @param array<string, mixed> $options Field name.
130
+ * @param string $constantValue Constant value.
131
+ * @param string $optionName Option name.
132
+ * @param string $constantName Constant name.
131
133
* @param string $label Field label.
132
134
* @param string $help Field help.
133
135
*
134
136
* @return array<string, mixed>
135
137
*/
136
- public static function getInputFieldWithGlobalVariable (array $ options , string $ label , string $ help = '' ): array
137
- {
138
+ public static function getInputFieldWithGlobalVariable (
139
+ string $ constantValue ,
140
+ string $ optionName ,
141
+ string $ constantName ,
142
+ string $ label ,
143
+ string $ help = ''
144
+ ): array {
145
+ $ options = static ::getOptionFieldWithConstant ($ constantValue , $ optionName , $ constantName );
146
+
138
147
$ internalHelp = !empty ($ help ) ? $ help . '<br/><br/> ' : '' ;
139
- $ optionsHelp = !empty ($ options ['help ' ]) ? $ internalHelp . $ options ['help ' ] : $ help ;
148
+ $ optionsHelp = !empty ($ options ['help ' ]) ? "{ $ internalHelp}{ $ options ['help ' ]}" : $ help ;
140
149
141
150
return [
142
151
'component ' => 'input ' ,
@@ -153,19 +162,29 @@ public static function getInputFieldWithGlobalVariable(array $options, string $l
153
162
/**
154
163
* Get settings password field with global variable.
155
164
*
156
- * @param array<string, mixed> $options Field name.
165
+ * @param string $constantValue Constant value.
166
+ * @param string $optionName Option name.
167
+ * @param string $constantName Constant name.
157
168
* @param string $label Field label.
169
+ * @param string $help Field help.
158
170
*
159
171
* @return array<string, mixed>
160
172
*/
161
- public static function getPasswordFieldWithGlobalVariable (array $ options , string $ label ): array
162
- {
173
+ public static function getPasswordFieldWithGlobalVariable (
174
+ string $ constantValue ,
175
+ string $ optionName ,
176
+ string $ constantName ,
177
+ string $ label ,
178
+ string $ help = ''
179
+ ): array {
180
+ $ options = static ::getOptionFieldWithConstant ($ constantValue , $ optionName , $ constantName );
181
+
163
182
$ general = [
164
183
'component ' => 'input ' ,
165
184
'inputName ' => $ options ['name ' ],
166
185
'inputFieldLabel ' => $ label ,
167
186
'inputIsRequired ' => true ,
168
- 'inputFieldHelp ' => $ options ['help ' ],
187
+ 'inputFieldHelp ' => "{ $ options ['help ' ]}{ $ help }" ,
169
188
'inputIsDisabled ' => $ options ['isDisabled ' ],
170
189
];
171
190
@@ -205,6 +224,62 @@ public static function getPasswordFieldWithGlobalVariable(array $options, string
205
224
);
206
225
}
207
226
227
+ /**
228
+ * Get option with constant.
229
+ *
230
+ * @param string $constantValue Constant value.
231
+ * @param string $optionName Option name.
232
+ * @param string $constantName Constant name.
233
+ *
234
+ * @return array<string, mixed>
235
+ */
236
+ public static function getOptionFieldWithConstant (
237
+ string $ constantValue ,
238
+ string $ optionName ,
239
+ string $ constantName
240
+ ): array {
241
+ $ isDisabled = !empty ($ constantValue );
242
+ $ value = '' ;
243
+ $ isContantValueUsed = false ;
244
+
245
+ $ option = UtilsSettingsHelper::getOptionValue ($ optionName );
246
+
247
+ if (empty ($ constantValue )) {
248
+ $ value = $ option ;
249
+ } else {
250
+ $ value = $ constantValue ;
251
+ $ isContantValueUsed = true ;
252
+ }
253
+
254
+ $ helpOutput = '' ;
255
+
256
+ if ($ constantName ) {
257
+ // translators: %s will be replaced with global variable name.
258
+ $ helpOutput .= \sprintf (\__ ('
259
+ <details class="is-filter-applied">
260
+ <summary>Available global variables</summary>
261
+ <ul>
262
+ <li>%s</li>
263
+ </ul>
264
+ <br />
265
+ This field value can also be set using a global variable via code.
266
+ </details> ' , 'eightshift-forms ' ), $ constantName );
267
+
268
+ if ($ isContantValueUsed ) {
269
+ $ helpOutput = '<span class="is-filter-applied"> ' . \__ ('This field value is set with a global variable via code. ' , 'eightshift-forms ' ) . '</span> ' ;
270
+ }
271
+ }
272
+
273
+ return [
274
+ 'name ' => UtilsSettingsHelper::getOptionName ($ optionName ),
275
+ 'value ' => $ value ,
276
+ 'isDisabled ' => $ isDisabled ,
277
+ 'help ' => $ helpOutput ,
278
+ 'constantValue ' => $ constantValue ,
279
+ 'isContantValueUsed ' => $ isContantValueUsed ,
280
+ ];
281
+ }
282
+
208
283
/**
209
284
* Setting output for Test api connection
210
285
*
0 commit comments