Skip to content

Commit 10ea0d3

Browse files
committed
Updating fields with debug filter
1 parent d80f2d0 commit 10ea0d3

File tree

5 files changed

+111
-101
lines changed

5 files changed

+111
-101
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).
66

7+
## [3.1.3]
8+
9+
### Removed
10+
11+
- `SETTINGS_DEBUG_FORCE_DISABLED_FIELDS` constant.
12+
- `isDeveloperForceDisabledFieldsActive()` method.
13+
- `getSettingsDisabledOutputWithDebugFilter` method.
14+
15+
### Added
16+
17+
- `getOptionWithConstant` method.
18+
719
## [3.1.2]
820

921
### Removed
@@ -342,6 +354,7 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
342354

343355
- Initial production release.
344356

357+
[3.1.3]: https://github.com/infinum/eightshift-forms-utils/compare/3.1.2...3.1.3
345358
[3.1.2]: https://github.com/infinum/eightshift-forms-utils/compare/3.1.1...3.1.2
346359
[3.1.1]: https://github.com/infinum/eightshift-forms-utils/compare/3.1.0...3.1.1
347360
[3.1.0]: https://github.com/infinum/eightshift-forms-utils/compare/3.0.18...3.1.0

src/Config/UtilsConfig.php

-7
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,6 @@ class UtilsConfig
253253
*/
254254
public const SETTINGS_DEBUG_QM_LOG = 'skip-qm-log';
255255

256-
/**
257-
* Debug settings name - skip force disabled fields mode.
258-
*
259-
* @var string
260-
*/
261-
public const SETTINGS_DEBUG_FORCE_DISABLED_FIELDS = 'skip-force-disabled-fields';
262-
263256
// ------------------------------------------------------------------
264257
// SETTINGS TYPES
265258
// ------------------------------------------------------------------

src/Helpers/UtilsDeveloperHelper.php

-10
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,6 @@ public static function isDeveloperQMLogActive(): bool
9797
return \apply_filters(UtilsConfig::FILTER_SETTINGS_IS_DEBUG_ACTIVE, false, UtilsConfig::SETTINGS_DEBUG_QM_LOG);
9898
}
9999

100-
/**
101-
* Check if Force Disabled Fields mode is active.
102-
*
103-
* @return boolean
104-
*/
105-
public static function isDeveloperForceDisabledFieldsActive(): bool
106-
{
107-
return \apply_filters(UtilsConfig::FILTER_SETTINGS_IS_DEBUG_ACTIVE, false, UtilsConfig::SETTINGS_DEBUG_FORCE_DISABLED_FIELDS);
108-
}
109-
110100
/**
111101
* Set and output data to output log using Query Monitor plugin.
112102
*

src/Helpers/UtilsSettingsHelper.php

+15-76
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ public static function getOptionValue(string $key): string
156156
return (string) \get_option(self::getOptionName($key), '');
157157
}
158158

159+
/**
160+
* Get option with constant.
161+
*
162+
* @param string $constantValue Constant value.
163+
* @param string $key Option name.
164+
*
165+
* @return string
166+
*/
167+
public static function getOptionWithConstant(
168+
string $constantValue,
169+
string $key,
170+
): string {
171+
return empty($constantValue) ? self::getOptionValue($key) : $constantValue;
172+
}
173+
159174
/**
160175
* Get option value with fallback.
161176
*
@@ -331,82 +346,6 @@ public static function sortSettingsByOrder(array $data): array
331346
return $output;
332347
}
333348

334-
// --------------------------------------------------
335-
// Complex helper methods
336-
// --------------------------------------------------
337-
338-
/**
339-
* Get settings option value or global variable depending on the debug settings.
340-
*
341-
* @param string $constantValue Constant value.
342-
* @param string $optionName Option name.
343-
* @param string $constantName Constant name.
344-
*
345-
* @return array<string, mixed>
346-
*/
347-
public static function getSettingsDisabledOutputWithDebugFilter(
348-
string $constantValue,
349-
string $optionName,
350-
string $constantName = ''
351-
): array {
352-
$isDisabled = !empty($constantValue);
353-
$value = '';
354-
$isContantValueUsed = false;
355-
356-
$option = self::getOptionValue($optionName);
357-
358-
if (empty($constantValue)) {
359-
$value = $option;
360-
} else {
361-
$value = $constantValue;
362-
$isContantValueUsed = true;
363-
}
364-
365-
$isOverrideActive = UtilsDeveloperHelper::isDeveloperForceDisabledFieldsActive();
366-
367-
if ($isOverrideActive) {
368-
$isDisabled = false;
369-
if (empty($option)) {
370-
$value = $constantValue;
371-
$isContantValueUsed = true;
372-
} else {
373-
$value = $option;
374-
}
375-
}
376-
377-
$helpOutput = '';
378-
379-
if ($constantName) {
380-
// translators: %s will be replaced with global variable name.
381-
$helpOutput .= \sprintf(\__('
382-
<details class="is-filter-applied">
383-
<summary>Available global variables</summary>
384-
<ul>
385-
<li>%s</li>
386-
</ul>
387-
<br />
388-
This field value can also be set using a global variable via code.
389-
</details>', 'eightshift-forms'), $constantName);
390-
391-
if ($isContantValueUsed) {
392-
$helpOutput = '<span class="is-filter-applied">' . \__('This field value is set with a global variable via code.', 'eightshift-forms') . '</span>';
393-
}
394-
395-
if ($isOverrideActive) {
396-
$helpOutput .= '<span class="is-debug-applied">' . \__('Debug disable option override is active. Be careful what value is used!', 'eightshift-forms') . '</span>';
397-
}
398-
}
399-
400-
return [
401-
'name' => self::getOptionName($optionName),
402-
'value' => $value,
403-
'isDisabled' => $isDisabled,
404-
'help' => $helpOutput,
405-
'constantValue' => $constantValue,
406-
'isContantValueUsed' => $isContantValueUsed,
407-
];
408-
}
409-
410349
// --------------------------------------------------
411350
// Private helper methods
412351
// --------------------------------------------------

src/Helpers/UtilsSettingsOutputHelper.php

+83-8
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,25 @@ public static function getMiscDisclaimer(string $type = ''): array
127127
/**
128128
* Get settings input field with global variable.
129129
*
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.
131133
* @param string $label Field label.
132134
* @param string $help Field help.
133135
*
134136
* @return array<string, mixed>
135137
*/
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+
138147
$internalHelp = !empty($help) ? $help . '<br/><br/>' : '';
139-
$optionsHelp = !empty($options['help']) ? $internalHelp . $options['help'] : $help;
148+
$optionsHelp = !empty($options['help']) ? "{$internalHelp}{$options['help']}" : $help;
140149

141150
return [
142151
'component' => 'input',
@@ -153,19 +162,29 @@ public static function getInputFieldWithGlobalVariable(array $options, string $l
153162
/**
154163
* Get settings password field with global variable.
155164
*
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.
157168
* @param string $label Field label.
169+
* @param string $help Field help.
158170
*
159171
* @return array<string, mixed>
160172
*/
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+
163182
$general = [
164183
'component' => 'input',
165184
'inputName' => $options['name'],
166185
'inputFieldLabel' => $label,
167186
'inputIsRequired' => true,
168-
'inputFieldHelp' => $options['help'],
187+
'inputFieldHelp' => "{$options['help']}{$help}",
169188
'inputIsDisabled' => $options['isDisabled'],
170189
];
171190

@@ -205,6 +224,62 @@ public static function getPasswordFieldWithGlobalVariable(array $options, string
205224
);
206225
}
207226

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+
208283
/**
209284
* Setting output for Test api connection
210285
*

0 commit comments

Comments
 (0)