PluginProbe
User Access Manager / 2.3.20
User Access Manager v2.3.20
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Controller / Backend / ControllerTabNavigationTrait.php

ControllerTabNavigationTrait.php in User Access Manager 2.3.20, at src/Controller/Backend/ControllerTabNavigationTrait.php

60 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Controller\Backend;
6
7 trait ControllerTabNavigationTrait
8 {
9 abstract public function getRequestUrl(): string;
10
11 abstract public function getRequestParameter(string $name, $default = null): mixed;
12
13 abstract public function getGroupText(string $key, bool $description = false): string;
14
15 abstract public function getGroupSectionText(string $key): string;
16
17 abstract public function getTabGroups(): array;
18
19 public function getCurrentTabGroup(): string
20 {
21 $groups = $this->getTabGroups();
22 $keys = array_keys($groups);
23 $default = (string) reset($keys);
24 $group = (string) $this->getRequestParameter('tab_group', $default);
25
26 return isset($groups[$group]) === true ? $group : $default;
27 }
28
29 public function getSections(): array
30 {
31 $groups = $this->getTabGroups();
32
33 return $groups[$this->getCurrentTabGroup()] ?? [];
34 }
35
36 public function getCurrentTabGroupSection(): string
37 {
38 $groups = $this->getTabGroups();
39 $sections = (array) ($groups[$this->getCurrentTabGroup()] ?? reset($groups));
40 $default = (string) reset($sections);
41 $section = (string) $this->getRequestParameter('tab_group_section', $default);
42
43 return in_array($section, $sections, true) === true ? $section : $default;
44 }
45
46 public function getTabGroupLink(string $groupKey): string
47 {
48 $rawUrl = $this->getRequestUrl();
49 $url = preg_replace('/&amp;tab_group[^&]*/i', '', $rawUrl);
50 return $url . '&tab_group=' . $groupKey;
51 }
52
53 public function getTabGroupSectionLink(string $groupKey, string $sectionKey): string
54 {
55 $rawUrl = $this->getTabGroupLink($groupKey);
56 $url = preg_replace('/&amp;tab_group_section[^&]*/i', '', $rawUrl);
57 return $url . '&tab_group_section=' . $sectionKey;
58 }
59 }
60