Skip to content

Commit

Permalink
Fix fields.inc for EmailVerifiers to use grouped controls. (CFM-218)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen committed Sep 23, 2025
1 parent 46b3261 commit 3cfe0ea
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand All @@ -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"

Expand Down
43 changes: 23 additions & 20 deletions app/plugins/CoreEnroller/templates/EmailVerifiers/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,15 @@ $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 = <<<OTHER
<div class="field-suppliment">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="other-toggle" $checked/>
<label class="form-check-label" for="other-toggle">$otherLabel</label>
</div>
</div>
$otherField
OTHER;

$afterField = <<<'JS'
Expand Down Expand Up @@ -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'] = [
Expand Down
4 changes: 1 addition & 3 deletions app/templates/Standard/add-edit-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 2 additions & 0 deletions app/templates/element/form/fieldDiv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3cfe0ea

Please sign in to comment.