← All changes
|
src/Controller/Backend/ControllerTabNavigationTrait.php
+104
-23
2.3.20
→
2.1.11
View file →
| @@ -1,59 +1,140 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 2 | +/** | |
| 3 | + * ControllerTabNavigationTrait.php | |
| 4 | + * | |
| 5 | + * The ControllerTabNavigationTrait class file. | |
| 6 | + * | |
| 7 | + * PHP versions 5 | |
| 8 | + * | |
| 9 | + * @author Alexander Schneider <[email protected]> | |
| 10 | + * @copyright 2008-2017 Alexander Schneider | |
| 11 | + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 | |
| 12 | + * @version SVN: $id$ | |
| 13 | + * @link http://wordpress.org/extend/plugins/user-access-manager/ | |
| 14 | + */ | |
| 5 | 15 | namespace UserAccessManager\Controller\Backend; |
| 6 | 16 | |
| 17 | +/** | |
| 18 | + * Trait ControllerTabNavigationTrait | |
| 19 | + * | |
| 20 | + * @package UserAccessManager\Controller | |
| 21 | + */ | |
| 7 | 22 | trait ControllerTabNavigationTrait |
| 8 | 23 | { |
| 9 | - abstract public function getRequestUrl(): string; | |
| 24 | + /** | |
| 25 | + * Returns the current request url. | |
| 26 | + * | |
| 27 | + * @return string | |
| 28 | + */ | |
| 29 | + abstract public function getRequestUrl(); | |
| 10 | 30 | |
| 11 | - abstract public function getRequestParameter(string $name, $default = null): mixed; | |
| 31 | + /** | |
| 32 | + * Returns the request parameter. | |
| 33 | + * | |
| 34 | + * @param string $name | |
| 35 | + * @param mixed $default | |
| 36 | + * | |
| 37 | + * @return mixed | |
| 38 | + */ | |
| 39 | + abstract public function getRequestParameter($name, $default = null); | |
| 12 | 40 | |
| 13 | - abstract public function getGroupText(string $key, bool $description = false): string; | |
| 41 | + /** | |
| 42 | + * Translates the given group by the group key. | |
| 43 | + * | |
| 44 | + * @param string $key | |
| 45 | + * | |
| 46 | + * @return string | |
| 47 | + */ | |
| 48 | + abstract public function getGroupText($key); | |
| 14 | 49 | |
| 15 | - abstract public function getGroupSectionText(string $key): string; | |
| 50 | + /** | |
| 51 | + * Translates the given group section by the group key. | |
| 52 | + * | |
| 53 | + * @param string $key | |
| 54 | + * | |
| 55 | + * @return string | |
| 56 | + */ | |
| 57 | + abstract public function getGroupSectionText($key); | |
| 16 | 58 | |
| 17 | - abstract public function getTabGroups(): array; | |
| 59 | + /** | |
| 60 | + * Returns the tab groups. | |
| 61 | + * | |
| 62 | + * @return array | |
| 63 | + */ | |
| 64 | + abstract public function getTabGroups(); | |
| 18 | 65 | |
| 19 | - public function getCurrentTabGroup(): string | |
| 66 | + /** | |
| 67 | + * Returns the current tab group. | |
| 68 | + * | |
| 69 | + * @return string | |
| 70 | + */ | |
| 71 | + public function getCurrentTabGroup() | |
| 20 | 72 | { |
| 21 | 73 | $groups = $this->getTabGroups(); |
| 22 | 74 | $keys = array_keys($groups); |
| 23 | - $default = (string) reset($keys); | |
| 24 | - $group = (string) $this->getRequestParameter('tab_group', $default); | |
| 25 | 75 | |
| 26 | - return isset($groups[$group]) === true ? $group : $default; | |
| 76 | + return (string)$this->getRequestParameter('tab_group', reset($keys)); | |
| 27 | 77 | } |
| 28 | 78 | |
| 29 | - public function getSections(): array | |
| 79 | + /** | |
| 80 | + * Returns the tab group sections. | |
| 81 | + * | |
| 82 | + * @return array | |
| 83 | + */ | |
| 84 | + public function getSections() | |
| 30 | 85 | { |
| 31 | 86 | $groups = $this->getTabGroups(); |
| 87 | + $group = $this->getCurrentTabGroup(); | |
| 32 | 88 | |
| 33 | - return $groups[$this->getCurrentTabGroup()] ?? []; | |
| 89 | + return isset($groups[$group]) === true ? $groups[$group] : []; | |
| 34 | 90 | } |
| 35 | 91 | |
| 36 | - public function getCurrentTabGroupSection(): string | |
| 92 | + /** | |
| 93 | + * Returns the current tab group section. | |
| 94 | + * | |
| 95 | + * @return string | |
| 96 | + */ | |
| 97 | + public function getCurrentTabGroupSection() | |
| 37 | 98 | { |
| 38 | 99 | $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); | |
| 100 | + $group = $this->getCurrentTabGroup(); | |
| 42 | 101 | |
| 43 | - return in_array($section, $sections, true) === true ? $section : $default; | |
| 102 | + if (isset($groups[$group]) === true) { | |
| 103 | + $default = reset($groups[$group]); | |
| 104 | + } else { | |
| 105 | + $firstGroup = reset($groups); | |
| 106 | + $default = reset($firstGroup); | |
| 107 | + } | |
| 108 | + | |
| 109 | + return (string)$this->getRequestParameter('tab_group_section', $default); | |
| 44 | 110 | } |
| 45 | 111 | |
| 46 | - public function getTabGroupLink(string $groupKey): string | |
| 112 | + /** | |
| 113 | + * Returns the settings group link by the given group key. | |
| 114 | + * | |
| 115 | + * @param string $groupKey | |
| 116 | + * | |
| 117 | + * @return string | |
| 118 | + */ | |
| 119 | + public function getTabGroupLink($groupKey) | |
| 47 | 120 | { |
| 48 | 121 | $rawUrl = $this->getRequestUrl(); |
| 49 | 122 | $url = preg_replace('/&tab_group[^&]*/i', '', $rawUrl); |
| 50 | - return $url . '&tab_group=' . $groupKey; | |
| 123 | + return $url.'&tab_group='.$groupKey; | |
| 51 | 124 | } |
| 52 | 125 | |
| 53 | - public function getTabGroupSectionLink(string $groupKey, string $sectionKey): string | |
| 126 | + /** | |
| 127 | + * Returns the settings section link by the given group and section key. | |
| 128 | + * | |
| 129 | + * @param string $groupKey | |
| 130 | + * @param string $sectionKey | |
| 131 | + * | |
| 132 | + * @return string | |
| 133 | + */ | |
| 134 | + public function getTabGroupSectionLink($groupKey, $sectionKey) | |
| 54 | 135 | { |
| 55 | 136 | $rawUrl = $this->getTabGroupLink($groupKey); |
| 56 | 137 | $url = preg_replace('/&tab_group_section[^&]*/i', '', $rawUrl); |
| 57 | - return $url . '&tab_group_section=' . $sectionKey; | |
| 138 | + return $url.'&tab_group_section='.$sectionKey; | |
| 58 | 139 | } |
| 59 | 140 | } |