Skip to content

Commit

Permalink
[TASK] Aria-describedby for password field
Browse files Browse the repository at this point in the history
Add a aria-describedby attribute to link the password field with the
requirements description.

Resolves: #102100
Related: #97388
Releases: main, 12.4
Change-Id: Iec46dca547cf53764a47b18a54952aff8b33fdf5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81365
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
pschriner authored and lolli42 committed Oct 6, 2023
1 parent 026c1b1 commit 8015a32
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions typo3/sysext/setup/Classes/Controller/SetupModuleController.php
Expand Up @@ -436,18 +436,25 @@ protected function renderUserSetup(): array
$value = '';
$noAutocomplete = 'autocomplete="new-password" ';
}

$addPasswordRequirementsDescription = false;
if ($fieldName === 'password' && $this->passwordPolicyValidator->isEnabled() && $this->passwordPolicyValidator->hasRequirements()) {
$addPasswordRequirementsDescription = true;
}

$html = '<input id="field_' . htmlspecialchars($fieldName) . '"
type="' . htmlspecialchars($type) . '"
name="data' . $dataAdd . '[' . htmlspecialchars($fieldName) . ']" ' .
type="' . htmlspecialchars($type) . '" ' .
($addPasswordRequirementsDescription ? 'aria-describedby="description_' . htmlspecialchars($fieldName) . '" ' : '') .
'name="data' . $dataAdd . '[' . htmlspecialchars($fieldName) . ']" ' .
$noAutocomplete .
'value="' . htmlspecialchars((string)$value) . '" ' .
$more .
' />';

if ($fieldName === 'password' && $this->passwordPolicyValidator->isEnabled() && $this->passwordPolicyValidator->hasRequirements()) {
if ($addPasswordRequirementsDescription) {
$description = $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_password_policy.xlf:passwordRequirements.description');
$html .= '<p class="mt-2 mb-1 text-body-secondary">' . htmlspecialchars($description) . '</p>';
$html .= '<ul class="mb-0"><li class="text-body-secondary">' . implode('</li><li class="text-body-secondary">', $this->passwordPolicyValidator->getRequirements()) . '</li></ul>';
$html .= '<div id="description_' . htmlspecialchars($fieldName) . '"><p class="mt-2 mb-1 text-body-secondary">' . htmlspecialchars($description) . '</p>';
$html .= '<ul class="mb-0"><li class="text-body-secondary">' . implode('</li><li class="text-body-secondary">', $this->passwordPolicyValidator->getRequirements()) . '</li></ul></div>';
}

break;
Expand Down

0 comments on commit 8015a32

Please sign in to comment.