diff --git a/Classes/Utility/GuideUtility.php b/Classes/Utility/GuideUtility.php index 4bf3da2..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, @@ -110,14 +118,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,18 +135,14 @@ public function getRegisteredGuideTours() } $tours[$tourKey]['stepsCount'] = count($tours[$tourKey]['steps']); unset($tours[$tourKey]['steps']); - // Tour/Module is enabled for current user - if (!$this->moduleEnabled($tour['moduleName'])) { - // ..if not, remove that tour! - unset($tours[$tourKey]); - } } } return $tours; } /** - * 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 +150,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 +338,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