From a4ede327feea8bda6375b1b99a7ea69740f5cbd5 Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Tue, 23 Sep 2025 14:41:09 -0400 Subject: [PATCH] Fix fields.inc for EmailVerifiers to use grouped controls. (CFM-218) --- .../resources/locales/en_US/core_enroller.po | 4 +- .../templates/EmailVerifiers/fields.inc | 43 ++++++++++--------- app/templates/Standard/add-edit-view.php | 4 +- app/templates/element/form/fieldDiv.php | 2 + 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po index 666469f47..61bb47110 100644 --- a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po +++ b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po @@ -211,6 +211,9 @@ msgstr "Duration, in minutes, of the verification request before it expires" msgid "field.EmailVerifiers.verification_code_charset" msgstr "Verification Code Character Set" +msgid "field.EmailVerifiers.verification_code_charset.other_value" +msgstr "Other value" + msgid "field.EmailVerifiers.verification_code_charset.desc" msgstr "Set of characters for generating the verification code. Numbers and uppercase letters only." @@ -226,7 +229,6 @@ msgstr "Enable Attempt Blocker" msgid "field.EmailVerifiers.enable_blockonfailure.desc" msgstr "Enables blocking after consecutive failed attempts. Blocking duration increases exponentially based on the number of failed attempts." - msgid "field.EnrollmentAttributes.address_required_fields" msgstr "Required Address Fields" diff --git a/app/plugins/CoreEnroller/templates/EmailVerifiers/fields.inc b/app/plugins/CoreEnroller/templates/EmailVerifiers/fields.inc index 512cc6a3d..d3b08e4cb 100644 --- a/app/plugins/CoreEnroller/templates/EmailVerifiers/fields.inc +++ b/app/plugins/CoreEnroller/templates/EmailVerifiers/fields.inc @@ -45,18 +45,8 @@ $fields = [ ] ]; - -// Textbox for "Other" -$otherField = $this->Form->control('verification_code_charset', [ - 'type' => 'text', - 'label' => false, - 'id' => 'verification-code-charset', - 'style' => !empty($vv_obj?->verification_code_charset) ? '' : 'display: none;', - 'required' => false, -]); - $checked = !empty($vv_obj?->verification_code_charset) ? 'checked' : ''; -$otherLabel = __d('field','other.value'); +$otherLabel = __d('core_enroller','field.EmailVerifiers.verification_code_charset.other_value'); $beforeField = <<
@@ -64,7 +54,6 @@ $beforeField = <<$otherLabel
-$otherField OTHER; $afterField = <<<'JS' @@ -104,16 +93,30 @@ JS; $regexDisplayFirstTime = empty($vv_obj?->verification_code_charset) && empty($vv_obj?->verification_code_regex); $fields['verification_code_regex'] = [ 'fieldLabel' => __d('core_enroller','field.EmailVerifiers.verification_code_charset'), - 'fieldOptions' => [ - 'id' => 'verification-code-regex', - 'required' => false, - 'empty' => true, - 'style' => $regexDisplayFirstTime || !empty($vv_obj?->verification_code_regex) ? '' : 'display: none;', + 'groupedControls' => [ + 'verification_code_regex' => [ + 'fieldOptions' => [ + 'id' => 'verification-code-regex', + 'required' => false, + 'empty' => true, + 'style' => $regexDisplayFirstTime || !empty($vv_obj?->verification_code_regex) ? '' : 'display: none;', + ], + 'fieldType' => 'select', + 'fieldSelectOptions' => $permittedCharacters, + ], + 'verification_code_charset' => [ + 'fieldOptions' => [ + 'type' => 'text', + 'label' => false, + 'id' => 'verification-code-charset', + 'style' => !empty($vv_obj?->verification_code_charset) ? '' : 'display: none;', + 'required' => false, + 'checked' => !empty($vv_obj?->verification_code_charset) ? 'checked' : '' + ] + ] ], - 'fieldType' => 'select', - 'fieldSelectOptions' => $permittedCharacters, 'beforeField' => $beforeField, - 'afterField' => $afterField, + 'afterField' => $afterField ]; $fields['verification_code_length'] = [ diff --git a/app/templates/Standard/add-edit-view.php b/app/templates/Standard/add-edit-view.php index 50af7d212..7ce0990e8 100644 --- a/app/templates/Standard/add-edit-view.php +++ b/app/templates/Standard/add-edit-view.php @@ -230,15 +230,13 @@ if($this->Field->includesFileField($fields)) { // A file upload field is in the fields.inc configuration. // We will change the form encoding type to multipart/form-data. - // XXX Note: given that we need this in *exactly* one plugin, we might opt to - // test for the controller rather than scan the $fields[] array since that would always be faster. print $this->Form->create($vv_obj, ['type' => 'file']); } else { // We are using the standard form. print $this->Form->create($vv_obj); } - // Output the form fields (or values, in the case of view): + // Output the visible form fields (or values, in the case of view): if(!empty($fields)) { print $this->element('form/unorderedList', ['vv_fields' => $fields]); } diff --git a/app/templates/element/form/fieldDiv.php b/app/templates/element/form/fieldDiv.php index a72a23b70..828bb07e8 100644 --- a/app/templates/element/form/fieldDiv.php +++ b/app/templates/element/form/fieldDiv.php @@ -46,6 +46,8 @@ // beforeField and afterField are not used in FieldHelper so strip them from the arguments list: unset($vv_field_arguments['beforeField']); unset($vv_field_arguments['afterField']); + + // XXX Before we reset the vv_field_arguments, we should construct the fieldOptions array (post-flattening) $this->set('vv_field_arguments', $vv_field_arguments); // Info Div