From 45ecafe390d318d87f6ea14bfecd9efdbfe279d6 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 --- .htaccess | 4 +++ .../lib/Controller/CommonSettingsTrait.php | 36 ++++++++++++------- core/templates/layout.user.php | 1 + 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.htaccess b/.htaccess index ce84f0698c76e..651b2478199ba 100644 --- a/.htaccess +++ b/.htaccess @@ -102,3 +102,7 @@ AddDefaultCharset utf-8 Options -Indexes +#### DO NOT CHANGE ANYTHING ABOVE THIS LINE #### + +ErrorDocument 403 / +ErrorDocument 404 / diff --git a/apps/settings/lib/Controller/CommonSettingsTrait.php b/apps/settings/lib/Controller/CommonSettingsTrait.php index 2eb7b4ccf99bd..fe3697ebbaaa1 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; @@ -53,11 +54,13 @@ trait CommonSettingsTrait { /** @var ISubAdmin */ private $subAdmin; + /** @var ?IIconSection */ + private $activeSection = null; + /** - * @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' => [] @@ -73,9 +76,13 @@ private function getNavigationParameters($currentType, $currentSection) { ]; } + /** + * @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') { @@ -92,6 +99,10 @@ protected function formatSections(array $sections, string $currentSection, strin $active = $section->getID() === $currentSection && $type === $currentType; + if ($active) { + $this->activeSection = $section; + } + $templateParameters[] = [ 'anchor' => $section->getID(), 'section-name' => $section->getName(), @@ -105,21 +116,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 +140,16 @@ 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)); + if ($this->activeSection !== null) { + $templateParams = array_merge($templateParams, [ + 'pageTitle' => $this->activeSection->getName() + ]); + } return new TemplateResponse('settings', 'settings/frame', $templateParams); } diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 8bdb4811df9fc..97fdf5067138e 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()); ?>