| 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 |
|
| 24 |
return (string) $this->getRequestParameter('tab_group', reset($keys)); |
| 25 |
} |
| 26 |
|
| 27 |
public function getSections(): array |
| 28 |
{ |
| 29 |
$groups = $this->getTabGroups(); |
| 30 |
|
| 31 |
return $groups[$this->getCurrentTabGroup()] ?? []; |
| 32 |
} |
| 33 |
|
| 34 |
public function getCurrentTabGroupSection(): string |
| 35 |
{ |
| 36 |
$groups = $this->getTabGroups(); |
| 37 |
$sections = $groups[$this->getCurrentTabGroup()] ?? reset($groups); |
| 38 |
|
| 39 |
return (string) $this->getRequestParameter('tab_group_section', reset($sections)); |
| 40 |
} |
| 41 |
|
| 42 |
public function getTabGroupLink(string $groupKey): string |
| 43 |
{ |
| 44 |
$rawUrl = $this->getRequestUrl(); |
| 45 |
$url = preg_replace('/&tab_group[^&]*/i', '', $rawUrl); |
| 46 |
return $url . '&tab_group=' . $groupKey; |
| 47 |
} |
| 48 |
|
| 49 |
public function getTabGroupSectionLink(string $groupKey, string $sectionKey): string |
| 50 |
{ |
| 51 |
$rawUrl = $this->getTabGroupLink($groupKey); |
| 52 |
$url = preg_replace('/&tab_group_section[^&]*/i', '', $rawUrl); |
| 53 |
return $url . '&tab_group_section=' . $sectionKey; |
| 54 |
} |
| 55 |
} |
| 56 |
|