Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accessibility of the title of the settings #29881

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions apps/settings/lib/Controller/CommonSettingsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<array{anchor: string, section-name: string, active: bool, icon: string}>
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
*/
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') {
Expand Down Expand Up @@ -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<int, list<\OCP\Settings\ISettings>> $settings
* @return array
* @return array{content: string}
*/
private function formatSettings(array $settings): array {
$html = '';
Expand All @@ -133,7 +133,7 @@ private function formatSettings(array $settings): array {
return ['content' => $html];
}

private function getIndexResponse($type, $section) {
private function getIndexResponse(string $type, string $section): TemplateResponse {
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
if ($type === 'personal') {
$this->navigationManager->setActiveEntry('settings');
} elseif ($type === 'admin') {
Expand All @@ -143,6 +143,10 @@ private function getIndexResponse($type, $section) {
$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);
}
Expand Down
1 change: 1 addition & 0 deletions core/templates/layout.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<meta charset="utf-8">
<title>
<?php
p(!empty($_['pageTitle'])?$_['pageTitle'].' - ':'');
p(!empty($_['application'])?$_['application'].' - ':'');
p($theme->getTitle());
?>
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Settings/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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',
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Settings/IIconSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions lib/public/Settings/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}