Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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