From e9a87b95a6c856bec3a074bebe04fccbbded7faa Mon Sep 17 00:00:00 2001 From: Dan Untenzu Date: Fri, 23 Feb 2018 13:06:17 +0100 Subject: [PATCH 1/2] [FEATURE] Better readability for module checks --- Classes/Utility/GuideUtility.php | 61 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/Classes/Utility/GuideUtility.php b/Classes/Utility/GuideUtility.php index 4bf3da2..b5603d2 100644 --- a/Classes/Utility/GuideUtility.php +++ b/Classes/Utility/GuideUtility.php @@ -110,14 +110,15 @@ public function getRegisteredGuideTours() } else { $tours[$tour['name']] = $tour; } - // Be sure disabled is available + + // Be sure disabled key is available if (!isset($tours[$tourKey]['disabled'])) { $tours[$tourKey]['disabled'] = false; } - // Title and description + // Set title and description $tours[$tourKey]['title'] = $this->translate($tours[$tourKey]['title']); $tours[$tourKey]['description'] = $this->translate($tours[$tourKey]['description']); - // Generate an id + // Generate a tour id for assets $tours[$tourKey]['id'] = GeneralUtility::camelCaseToLowerCaseUnderscored($tour['name']); $tours[$tourKey]['id'] = 'guide-tour-' . str_replace('_', '-', $tours[$tourKey]['id']); // Remove steps @@ -126,9 +127,10 @@ public function getRegisteredGuideTours() } $tours[$tourKey]['stepsCount'] = count($tours[$tourKey]['steps']); unset($tours[$tourKey]['steps']); - // Tour/Module is enabled for current user + + // Check if requested module is enabled for current user if (!$this->moduleEnabled($tour['moduleName'])) { - // ..if not, remove that tour! + // …if not, remove that tour unset($tours[$tourKey]); } } @@ -137,7 +139,8 @@ public function getRegisteredGuideTours() } /** - * Passed module is enabled for current backend user? + * Check if current backend user is allowed to access the passed module of the tour + * * @param $moduleName * @return bool */ @@ -145,31 +148,29 @@ public function moduleEnabled($moduleName) { $enabled = false; $backendUser = $this->getBackendUserAuthentication(); - if ($backendUser->isAdmin()) { - $enabled = true; - } else { - if ($moduleName === 'core') { + + if ($moduleName === 'core' || $backendUser->isAdmin()) { + return true; + } + + if (!($this->backendModuleRepository instanceof BackendModuleRepository)) { + $this->backendModuleRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Domain\\Repository\\Module\\BackendModuleRepository'); + } + $modules = $this->backendModuleRepository->loadAllowedModules(); + /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $module */ + foreach ($modules as $module) { + $children = $module->getChildren(); + if (!empty($children)) { + /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $child */ + foreach ($children as $child) { + if ($moduleName === $child->getName()) { $enabled = true; - } else { - if (!($this->backendModuleRepository instanceof BackendModuleRepository)) { - $this->backendModuleRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Domain\\Repository\\Module\\BackendModuleRepository'); - } - $modules = $this->backendModuleRepository->loadAllowedModules(); - /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $module */ - foreach ($modules as $module) { - $children = $module->getChildren(); - if (!empty($children)) { - /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $child */ - foreach ($children as $child) { - if ($moduleName === $child->getName()) { - $enabled = true; - break(2); - } - } - } - } + break 2; + } } + } } + return $enabled; } @@ -335,7 +336,9 @@ public function isGuidedTourActivated() } /** - * Set a tour as disabled + * Let user disable a tour (“Dont show again”). + * Tour will still be available in the list. + * * @param string $tourName Name of the guided tour * @param bool $disabled Disabled true/false * @return array From 2faf386062a5cbc562c5eb32113726bdd3a89957 Mon Sep 17 00:00:00 2001 From: Dan Untenzu Date: Fri, 23 Feb 2018 13:18:32 +0100 Subject: [PATCH 2/2] [FEATURE] Hide tours MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each tour may be hidden from the user permanently using the option »hide = 1«. To hide the AboutModule tour for a special user, just add the following code to his User-TSconfig: mod.guide.tours.AboutModule.hide = 1 Refs #10 --- Classes/Utility/GuideUtility.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Classes/Utility/GuideUtility.php b/Classes/Utility/GuideUtility.php index b5603d2..64d27b2 100644 --- a/Classes/Utility/GuideUtility.php +++ b/Classes/Utility/GuideUtility.php @@ -103,6 +103,14 @@ public function getRegisteredGuideTours() if(count($tours) >0) { foreach ($tours as $tourKey => $tour) { $tour['name'] = $tourKey; + + // Check if tour should be hidden from the user, or if + // requested tour module is not enabled for current user + if (false === empty($tours[$tourKey]['hide']) || false === $this->moduleEnabled($tour['moduleName'])) { + unset($tours[$tourKey]); + continue; + } + // Merge user configuration if (isset($backendUser->uc['moduleData']['guide'][$tour['name']])) { $tours[$tour['name']] = array_merge($tour, @@ -127,12 +135,6 @@ public function getRegisteredGuideTours() } $tours[$tourKey]['stepsCount'] = count($tours[$tourKey]['steps']); unset($tours[$tourKey]['steps']); - - // Check if requested module is enabled for current user - if (!$this->moduleEnabled($tour['moduleName'])) { - // …if not, remove that tour - unset($tours[$tourKey]); - } } } return $tours;