From 046d5451b15d46581cde846676e0b6d631fedbb7 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 24 Nov 2021 14:08:16 +0100 Subject: [PATCH] Improve accessibility of the title of the settings Before every setting page had the same title and this is causing issues for screenreaders since they can't differenciate the title of page. Now a new variable is available for apps to declare the page subtitle. This new variable is implemented for the settings app and while at it I added a bit more type hinting to the stuff I touched :) Signed-off-by: Carl Schwan --- .../lib/Controller/CommonSettingsTrait.php | 34 +++++++++++-------- core/templates/layout.user.php | 1 + lib/private/Settings/Manager.php | 7 ++++ lib/public/Settings/IIconSection.php | 4 +-- lib/public/Settings/IManager.php | 6 ++++ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/apps/settings/lib/Controller/CommonSettingsTrait.php b/apps/settings/lib/Controller/CommonSettingsTrait.php index 2eb7b4ccf99bd..7cb706bb3a6c7 100644 --- a/apps/settings/lib/Controller/CommonSettingsTrait.php +++ b/apps/settings/lib/Controller/CommonSettingsTrait.php @@ -33,6 +33,7 @@ use OCP\IGroupManager; use OCP\INavigationManager; use OCP\IUserSession; +use OCP\Settings\IIconSection; use OCP\Settings\IManager as ISettingsManager; use OCP\Settings\ISettings; @@ -54,28 +55,31 @@ trait CommonSettingsTrait { private $subAdmin; /** - * @param string $currentSection - * @return array + * @return array{forms: array{personal: array, admin: array}} */ - private function getNavigationParameters($currentType, $currentSection) { + private function getNavigationParameters(string $currentType, string $currentSection): array { $templateParameters = [ 'personal' => $this->formatPersonalSections($currentType, $currentSection), 'admin' => [] ]; $templateParameters['admin'] = $this->formatAdminSections( - $currentType, - $currentSection - ); + $currentType, + $currentSection + ); return [ 'forms' => $templateParameters ]; } + /** + * @param IIconSection[][] $sections + * @psam-param 'admin'|'personal' $type + * @return list + */ protected function formatSections(array $sections, string $currentSection, string $type, string $currentType): array { $templateParameters = []; - /** @var \OCP\Settings\IIconSection[] $prioritizedSections */ foreach ($sections as $prioritizedSections) { foreach ($prioritizedSections as $section) { if ($type === 'admin') { @@ -105,21 +109,17 @@ protected function formatSections(array $sections, string $currentSection, strin protected function formatPersonalSections(string $currentType, string $currentSections): array { $sections = $this->settingsManager->getPersonalSections(); - $templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType); - - return $templateParameters; + return $this->formatSections($sections, $currentSections, 'personal', $currentType); } protected function formatAdminSections(string $currentType, string $currentSections): array { $sections = $this->settingsManager->getAdminSections(); - $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType); - - return $templateParameters; + return $this->formatSections($sections, $currentSections, 'admin', $currentType); } /** * @param array> $settings - * @return array + * @return array{content: string} */ private function formatSettings(array $settings): array { $html = ''; @@ -133,11 +133,15 @@ private function formatSettings(array $settings): array { return ['content' => $html]; } - private function getIndexResponse($type, $section) { + private function getIndexResponse(string $type, string $section): TemplateResponse { $this->navigationManager->setActiveEntry('settings'); $templateParams = []; $templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section)); $templateParams = array_merge($templateParams, $this->getSettings($section)); + $activeSection = $this->settingsManager->getSection($type, $section); + if ($activeSection) { + $templateParams['pageTitle'] = $activeSection->getName(); + } return new TemplateResponse('settings', 'settings/frame', $templateParams); } diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 82626733bd252..ecb0c614dd43e 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -18,6 +18,7 @@ <?php + p(!empty($_['pageTitle'])?$_['pageTitle'].' - ':''); p(!empty($_['application'])?$_['application'].' - ':''); p($theme->getTitle()); ?> diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 84fbf9426b094..ed331c597252d 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -145,6 +145,13 @@ protected function getSections(string $type): array { return $this->sections[$type]; } + public function getSection(string $type, string $sectionId): ?IIconSection { + if (isset($this->sections[$type]) && isset($this->sections[$type][$sectionId])) { + return $this->sections[$type][$sectionId]; + } + return null; + } + protected function isKnownDuplicateSectionId(string $sectionID): bool { return in_array($sectionID, [ 'connected-accounts', diff --git a/lib/public/Settings/IIconSection.php b/lib/public/Settings/IIconSection.php index c56565fbf8598..bb9b2e94b0dd1 100644 --- a/lib/public/Settings/IIconSection.php +++ b/lib/public/Settings/IIconSection.php @@ -31,7 +31,7 @@ interface IIconSection { * returns the ID of the section. It is supposed to be a lower case string, * e.g. 'ldap' * - * @returns string + * @return string * @since 9.1 */ public function getID(); @@ -59,7 +59,7 @@ public function getPriority(); * returns the relative path to an 16*16 icon describing the section. * e.g. '/core/img/places/files.svg' * - * @returns string + * @return string * @since 12 */ public function getIcon(); diff --git a/lib/public/Settings/IManager.php b/lib/public/Settings/IManager.php index 2ec3fb0fd216d..10de596dbead4 100644 --- a/lib/public/Settings/IManager.php +++ b/lib/public/Settings/IManager.php @@ -116,4 +116,10 @@ public function getAllAllowedAdminSettings(IUser $user): array; * @since 13.0.0 */ public function getPersonalSettings($section): array; + + /** + * Get a specific section by type and id + * @since 25.0.0 + */ + public function getSection(string $type, string $sectionId): ?IIconSection; }