‪TYPO3CMS  ‪main
FrontendWorkspaceRestriction.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 
31 {
35  protected ‪$workspaceId;
36 
41 
45  protected ‪$enforceLiveRowsOnly;
46 
52  public function ‪__construct(int ‪$workspaceId = null, bool ‪$includeRowsForWorkspacePreview = null, bool ‪$enforceLiveRowsOnly = true)
53  {
54  trigger_error('FrontendWorkspaceRestriction will be removed in TYPO3 v13.0. Use WorkspaceRestriction instead.', E_USER_DEPRECATED);
55  $globalWorkspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
56  $this->workspaceId = ‪$workspaceId ?? $globalWorkspaceId;
57  $this->includeRowsForWorkspacePreview = ‪$includeRowsForWorkspacePreview ?? $globalWorkspaceId > 0;
58  $this->enforceLiveRowsOnly = ‪$enforceLiveRowsOnly;
59  }
60 
69  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
70  {
71  $constraints = [];
72  foreach ($queriedTables as $tableAlias => $tableName) {
73  $workspaceEnabled = ‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? null;
74  if (!empty($workspaceEnabled)) {
75  if (!$this->includeRowsForWorkspacePreview) {
76  // Filter out placeholder records (new/moved/deleted items)
77  // in case we are NOT in a versioning preview (That means we are online!)
78  $constraints[] = $expressionBuilder->‪lte(
79  $tableAlias . '.t3ver_state',
80  // Trigger __toString(), then cast int
82  );
83  } elseif ($tableName !== 'pages') {
84  // Show only records of the live and current workspace in case we are in a versioning preview
85  $constraints[] = $expressionBuilder->‪or(
86  $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', 0),
87  $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', (int)$this->workspaceId)
88  );
89  }
90  // Filter out versioned records
91  if ($this->enforceLiveRowsOnly) {
92  $constraints[] = $expressionBuilder->‪eq($tableAlias . '.t3ver_oid', 0);
93  }
94  }
95  }
96  return $expressionBuilder->‪and(...$constraints);
97  }
98 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:36
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$enforceLiveRowsOnly
‪bool $enforceLiveRowsOnly
Definition: FrontendWorkspaceRestriction.php:42
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:128
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\or
‪or(CompositeExpression|string|null ... $expressions)
Definition: ExpressionBuilder.php:105
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction
Definition: FrontendWorkspaceRestriction.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: FrontendWorkspaceRestriction.php:34
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FrontendWorkspaceRestriction.php:66
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\lte
‪lte(string $fieldName, $value)
Definition: ExpressionBuilder.php:167
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\and
‪and(CompositeExpression|string|null ... $expressions)
Definition: ExpressionBuilder.php:97
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:55
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$includeRowsForWorkspacePreview
‪bool $includeRowsForWorkspacePreview
Definition: FrontendWorkspaceRestriction.php:38
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Core\Versioning\VersionState\DEFAULT_STATE
‪const DEFAULT_STATE
Definition: VersionState.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\__construct
‪__construct(int $workspaceId=null, bool $includeRowsForWorkspacePreview=null, bool $enforceLiveRowsOnly=true)
Definition: FrontendWorkspaceRestriction.php:49