‪TYPO3CMS  ‪main
ConditionMatcher.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
24 
34 {
38  protected ‪$context;
39 
46  protected array ‪$fullRootLine;
47 
56  public function ‪__construct(‪Context ‪$context = null, int ‪$pageId = null, array $rootLine = null, array ‪$fullRootLine = null)
57  {
58  trigger_error(
59  'The FE condition matcher has been deprecated and will be removed with TYPO3 v13. This logic' .
60  ' has been integrated into the new TypoScript parser structure, see IncludeTreeConditionMatcherVisitor',
61  E_USER_DEPRECATED
62  );
63  $this->context = ‪$context ?? GeneralUtility::makeInstance(Context::class);
64  $this->pageId = ‪$pageId;
65  // @todo: Accessing $GLOBALS['TSFE']->config['rootLine'] is rather useless here since it typically
66  // isn't set at this point in time in the FE processing chain. Use setRootline() instead.
67  $this->rootline = $rootLine ?? ‪$GLOBALS['TSFE']->config['rootLine'] ?? [];
68  $this->fullRootLine = ‪$fullRootLine ?? ‪$GLOBALS['TSFE']->rootLine ?? [];
70  }
71 
72  protected function ‪updateExpressionLanguageVariables(): void
73  {
74  $page = ‪$GLOBALS['TSFE']?->page ?? [];
75 
76  $tree = new \stdClass();
77  $tree->level = $this->rootline ? count($this->rootline) - 1 : 0;
78  $tree->rootLine = ‪$this->rootline;
79  $tree->rootLineIds = array_column($this->rootline, 'uid');
80  $tree->rootLineParentIds = array_slice(array_column($this->rootline, 'pid'), 1);
81  // We're feeding the "full" RootLine here, not the "local" one that stops at sys_template record having 'root' set.
82  // This is to be in-line with backend here: A 'backend_layout_next_level' on a page above sys_template 'root' page should
83  // still be considered. Additionally, $this->fullRootLine is "deepest page first, then up" for getLayoutForPage() to find
84  // the 'nearest' parent.
85  $tree->pagelayout = GeneralUtility::makeInstance(PageLayoutResolver::class)->getLayoutForPage($page, $this->fullRootLine);
86 
87  $frontendUserAspect = $this->context->getAspect('frontend.user');
88  $frontend = new \stdClass();
89  $frontend->user = new \stdClass();
90  $frontend->user->isLoggedIn = $frontendUserAspect->get('isLoggedIn');
91  $frontend->user->userId = $frontendUserAspect->get('id');
92  $frontend->user->userGroupList = implode(',', $frontendUserAspect->get('groupIds'));
93  $frontend->user->userGroupIds = $frontendUserAspect->get('groupIds');
94 
95  $backendUserAspect = $this->context->getAspect('backend.user');
96  $backend = new \stdClass();
97  $backend->user = new \stdClass();
98  $backend->user->isAdmin = $backendUserAspect->get('isAdmin');
99  $backend->user->isLoggedIn = $backendUserAspect->get('isLoggedIn');
100  $backend->user->userId = $backendUserAspect->get('id');
101  $backend->user->userGroupList = implode(',', $backendUserAspect->get('groupIds'));
102  $backend->user->userGroupIds = $backendUserAspect->get('groupIds');
103 
104  $workspaceAspect = $this->context->getAspect('workspace');
105  $workspace = new \stdClass();
106  $workspace->workspaceId = $workspaceAspect->get('id');
107  $workspace->isLive = $workspaceAspect->get('isLive');
108  $workspace->isOffline = $workspaceAspect->get('isOffline');
109 
110  $request = ‪$GLOBALS['TYPO3_REQUEST'] ?? null;
111  $site = null;
112  $siteLanguage = null;
113  if ($request instanceof ServerRequestInterface) {
114  $site = $request->getAttribute('site');
115  $siteLanguage = $request->getAttribute('language');
116  }
117  $this->expressionLanguageResolverVariables = [
118  'tree' => $tree,
119  'frontend' => $frontend,
120  'backend' => $backend,
121  'workspace' => $workspace,
122  'page' => $page,
123  'request' => new ‪RequestWrapper($request),
124  'date' => GeneralUtility::makeInstance(Context::class)->getAspect('date'),
125  'site' => $site,
126  'siteLanguage' => $siteLanguage,
127  'tsfe' => ‪$GLOBALS['TSFE'] ?? null,
128  ];
129  }
130 }
‪TYPO3\CMS\Core\ExpressionLanguage\RequestWrapper
Definition: RequestWrapper.php:35
‪TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\$fullRootLine
‪array $fullRootLine
Definition: ConditionMatcher.php:45
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher\$pageId
‪int $pageId
Definition: AbstractConditionMatcher.php:44
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:55
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher
Definition: AbstractConditionMatcher.php:37
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher\$rootline
‪array $rootline
Definition: AbstractConditionMatcher.php:54
‪TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\updateExpressionLanguageVariables
‪updateExpressionLanguageVariables()
Definition: ConditionMatcher.php:71
‪TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching
Definition: ConditionMatcher.php:16
‪TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\$context
‪Context $context
Definition: ConditionMatcher.php:37
‪TYPO3\CMS\Frontend\Page\PageLayoutResolver
Definition: PageLayoutResolver.php:32
‪TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
Definition: ConditionMatcher.php:34
‪TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\__construct
‪__construct(Context $context=null, int $pageId=null, array $rootLine=null, array $fullRootLine=null)
Definition: ConditionMatcher.php:55
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher\initializeExpressionLanguageResolver
‪initializeExpressionLanguageResolver()
Definition: AbstractConditionMatcher.php:78
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51