PluginProbe
User Access Manager / 2.3.0
User Access Manager v2.3.0
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.0, at src/Controller/Backend/ControllerTabNavigationTrait.php

69 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 /**
8 * Trait ControllerTabNavigationTrait
9 *
10 * @package UserAccessManager\Controller
11 */
12 trait ControllerTabNavigationTrait
13 {
14 abstract public function getRequestUrl(): string;
15
16 abstract public function getRequestParameter(string $name, $default = null): mixed;
17
18 abstract public function getGroupText(string $key): string;
19
20 abstract public function getGroupSectionText(string $key): string;
21
22 abstract public function getTabGroups(): array;
23
24 public function getCurrentTabGroup(): string
25 {
26 $groups = $this->getTabGroups();
27 $keys = array_keys($groups);
28
29 return (string) $this->getRequestParameter('tab_group', reset($keys));
30 }
31
32 public function getSections(): array
33 {
34 $groups = $this->getTabGroups();
35 $group = $this->getCurrentTabGroup();
36
37 return isset($groups[$group]) === true ? $groups[$group] : [];
38 }
39
40 public function getCurrentTabGroupSection(): string
41 {
42 $groups = $this->getTabGroups();
43 $group = $this->getCurrentTabGroup();
44
45 if (isset($groups[$group]) === true) {
46 $default = reset($groups[$group]);
47 } else {
48 $firstGroup = reset($groups);
49 $default = reset($firstGroup);
50 }
51
52 return (string) $this->getRequestParameter('tab_group_section', $default);
53 }
54
55 public function getTabGroupLink(string $groupKey): string
56 {
57 $rawUrl = $this->getRequestUrl();
58 $url = preg_replace('/&amp;tab_group[^&]*/i', '', $rawUrl);
59 return $url . '&tab_group=' . $groupKey;
60 }
61
62 public function getTabGroupSectionLink(string $groupKey, string $sectionKey): string
63 {
64 $rawUrl = $this->getTabGroupLink($groupKey);
65 $url = preg_replace('/&amp;tab_group_section[^&]*/i', '', $rawUrl);
66 return $url . '&tab_group_section=' . $sectionKey;
67 }
68 }
69