Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 37 additions & 32 deletions Classes/Utility/GuideUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,30 @@ 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,
$backendUser->uc['moduleData']['guide'][$tour['name']]);
} 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
Expand All @@ -126,50 +135,44 @@ 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
*/
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;
}

Expand Down Expand Up @@ -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
Expand Down