Created
July 6, 2015 14:05
-
-
Save lorenzulrich/086b6e81c3b0e05176b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My\Site\Userfunc; | |
/** | |
* This file is part of the TYPO3 CMS project. | |
* | |
* It is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU General Public License, either version 2 | |
* of the License, or any later version. | |
* | |
* For the full copyright and license information, please read the | |
* LICENSE.txt file that was distributed with this source code. | |
* | |
* The TYPO3 project - inspiring people to share! | |
*/ | |
class Condition { | |
/** | |
* Custom condition to check if access to the page is restricted by a frontend group (or "Show on any login") | |
* | |
* Usage in TypoScript: | |
* [userFunc = My\Site\Userfunc\Condition::pageHasAccessRestriction()] | |
* | |
* @return bool | |
*/ | |
public function pageHasAccessRestriction() { | |
$rootLine = $GLOBALS['TSFE']->rootLine; | |
foreach ($rootLine as $pageInRootLine) { | |
if (array_key_exists('fe_group', $pageInRootLine) && !empty($pageInRootLine['fe_group'])) { | |
// A fe_group is set (field is empty if no fe_group is set) | |
if ($pageInRootLine['uid'] === $GLOBALS['TSFE']->id) { | |
// We are on the current page, therefore this is an access protected page | |
return TRUE; | |
} else { | |
if ((bool)$pageInRootLine['extendToSubpages']) { | |
// Since we are not on the current page, we need to check if the page in the root line | |
// has extendToSubpages set and therefore the current page is access protected | |
return TRUE; | |
} | |
} | |
} | |
} | |
return FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment