‪TYPO3CMS  10.4
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 
22 
30 {
34  protected ‪$context;
35 
36  public function ‪__construct(‪Context ‪$context = null, int ‪$pageId = null, array $rootLine = null)
37  {
38  $this->context = ‪$context ?? GeneralUtility::makeInstance(Context::class);
39  $this->pageId = ‪$pageId ?? $this->‪determinePageId();
40  if ($rootLine === null) {
41  $rootLine = ‪BackendUtility::BEgetRootLine($this->pageId, '', true);
42  ksort($rootLine);
43  }
44  $this->rootline = $rootLine;
46  }
47 
48  protected function ‪updateExpressionLanguageVariables(): void
49  {
50  $treeLevel = $this->rootline ? count($this->rootline) - 1 : 0;
51  $tree = new \stdClass();
52  $tree->level = $treeLevel;
53  $tree->rootLine = ‪$this->rootline;
54  $tree->rootLineIds = array_column($this->rootline, 'uid');
55  $tree->rootLineParentIds = array_slice(array_column($this->rootline, 'pid'), 2);
56 
57  $backendUserAspect = $this->context->getAspect('backend.user');
58  $backend = new \stdClass();
59  $backend->user = new \stdClass();
60  $backend->user->isAdmin = $backendUserAspect->get('isAdmin');
61  $backend->user->isLoggedIn = $backendUserAspect->get('isLoggedIn');
62  $backend->user->userId = $backendUserAspect->get('id');
63  $backend->user->userGroupList = implode(',', $backendUserAspect->get('groupIds'));
64 
65  $workspaceAspect = $this->context->getAspect('workspace');
66  $workspace = new \stdClass();
67  $workspace->workspaceId = $workspaceAspect->get('id');
68  $workspace->isLive = $workspaceAspect->get('isLive');
69  $workspace->isOffline = $workspaceAspect->get('isOffline');
70 
71  $this->expressionLanguageResolverVariables = [
72  'tree' => $tree,
73  'backend' => $backend,
74  'workspace' => $workspace,
75  'page' => ‪BackendUtility::getRecord('pages', $this->pageId ?? $this->‪determinePageId()) ?: [],
76  ];
77  }
78 
87  private function ‪determinePageId(): int
88  {
89  ‪$pageId = 0;
90  $editStatement = GeneralUtility::_GP('edit');
91  $commandStatement = GeneralUtility::_GP('cmd');
92  // Determine id from module that was called with an id:
93  if ($id = (int)GeneralUtility::_GP('id')) {
94  ‪$pageId = $id;
95  } elseif (is_array($editStatement)) {
96  $table = key($editStatement);
97  $uidAndAction = current($editStatement);
98  $uid = key($uidAndAction);
99  $action = current($uidAndAction);
100  if ($action === 'edit') {
101  ‪$pageId = $this->‪getPageIdByRecord($table, $uid);
102  } elseif ($action === 'new') {
103  ‪$pageId = $this->‪getPageIdByRecord($table, $uid, true);
104  }
105  } elseif (is_array($commandStatement)) {
106  $table = key($commandStatement);
107  $uidActionAndTarget = current($commandStatement);
108  $uid = (int)key($uidActionAndTarget);
109  $actionAndTarget = current($uidActionAndTarget);
110  $action = key($actionAndTarget);
111  $target = current($actionAndTarget);
112  if ($action === 'delete') {
113  ‪$pageId = $this->‪getPageIdByRecord($table, $uid);
114  } elseif ($action === 'copy' || $action === 'move') {
115  ‪$pageId = $this->‪getPageIdByRecord($table, (int)($target['target'] ?? $target), true);
116  }
117  }
118  return ‪$pageId;
119  }
120 
129  private function ‪getPageIdByRecord($table, $id, $ignoreTable = false): int
130  {
131  ‪$pageId = 0;
132  $id = (int)$id;
133  if ($table && $id) {
134  if (($ignoreTable || $table === 'pages') && $id >= 0) {
135  ‪$pageId = $id;
136  } else {
137  $record = ‪BackendUtility::getRecordWSOL($table, abs($id), '*', '', false);
138  ‪$pageId = (int)$record['pid'];
139  }
140  }
141  return ‪$pageId;
142  }
143 }
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\updateExpressionLanguageVariables
‪updateExpressionLanguageVariables()
Definition: ConditionMatcher.php:47
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching
Definition: ConditionMatcher.php:16
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\determinePageId
‪int determinePageId()
Definition: ConditionMatcher.php:86
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
Definition: ConditionMatcher.php:30
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher\$pageId
‪int $pageId
Definition: AbstractConditionMatcher.php:41
‪TYPO3\CMS\Backend\Utility\BackendUtility\BEgetRootLine
‪static array BEgetRootLine($uid, $clause='', $workspaceOL=false, array $additionalFields=[])
Definition: BackendUtility.php:343
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\$context
‪Context $context
Definition: ConditionMatcher.php:33
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher
Definition: AbstractConditionMatcher.php:34
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher\$rootline
‪array $rootline
Definition: AbstractConditionMatcher.php:47
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\getPageIdByRecord
‪int getPageIdByRecord($table, $id, $ignoreTable=false)
Definition: ConditionMatcher.php:128
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher\__construct
‪__construct(Context $context=null, int $pageId=null, array $rootLine=null)
Definition: ConditionMatcher.php:35
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher\initializeExpressionLanguageResolver
‪initializeExpressionLanguageResolver()
Definition: AbstractConditionMatcher.php:71
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46