Typo3QuerySettings::setLanguageOverlayMode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
16
namespace TYPO3\CMS\Extbase\Persistence\Generic;
17
18
use Psr\Http\Message\ServerRequestInterface;
19
use TYPO3\CMS\Core\Context\Context;
20
use TYPO3\CMS\Core\Context\LanguageAspect;
21
use TYPO3\CMS\Core\Http\ApplicationType;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
24
25
/**
26
 * Query settings, reflects the settings unique to TYPO3 CMS.
27
 */
28
class Typo3QuerySettings implements QuerySettingsInterface
29
{
30
    protected ConfigurationManagerInterface $configurationManager;
31
    protected Context $context;
32
33
    /**
34
     * Flag if the storage page should be respected for the query.
35
     *
36
     * @var bool
37
     */
38
    protected $respectStoragePage = true;
39
40
    /**
41
     * the pid(s) of the storage page(s) that should be respected for the query.
42
     *
43
     * @var array
44
     */
45
    protected $storagePageIds = [];
46
47
    /**
48
     * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
49
     * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
50
     * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
51
     *
52
     * @var bool
53
     */
54
    protected $ignoreEnableFields = false;
55
56
    /**
57
     * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
58
     * to be ignored while building the query statement
59
     *
60
     * @var array
61
     */
62
    protected $enableFieldsToBeIgnored = [];
63
64
    /**
65
     * Flag whether deleted records should be included in the result set.
66
     *
67
     * @var bool
68
     */
69
    protected $includeDeleted = false;
70
71
    /**
72
     * Flag if the sys_language_uid should be respected (default is TRUE).
73
     *
74
     * @var bool
75
     */
76
    protected $respectSysLanguage = true;
77
78
    /**
79
     * Representing sys_language_overlay only valid for current context
80
     *
81
     * @var bool
82
     */
83
    protected $languageOverlayMode = true;
84
85
    /**
86
     * Representing sys_language_uid only valid for current context
87
     *
88
     * @var int
89
     */
90
    protected $languageUid = 0;
91
92
    public function __construct(
93
        Context $context,
94
        ConfigurationManagerInterface $configurationManager
95
    ) {
96
        // QuerySettings should always keep its own Context, as they can differ
97
        // Currently this is only used for reading, but might be improved in the future
98
        $this->context = clone $context;
99
        $this->configurationManager = $configurationManager;
100
        if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
101
            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
102
            && $this->configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
103
            $this->setIgnoreEnableFields(true);
104
        }
105
        /** @var LanguageAspect $languageAspect */
106
        $languageAspect = $this->context->getAspect('language');
107
        $this->setLanguageUid($languageAspect->getContentId());
108
        $this->setLanguageOverlayMode(false);
109
110
        if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
111
            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
112
        ) {
113
            $overlayMode = $languageAspect->getLegacyOverlayType() === 'hideNonTranslated' ? 'hideNonTranslated' : (bool)$languageAspect->getLegacyOverlayType();
114
            $this->setLanguageOverlayMode($overlayMode);
115
        } elseif ((int)GeneralUtility::_GP('L')) {
116
            // Set language from 'L' parameter
117
            $this->setLanguageUid((int)GeneralUtility::_GP('L'));
118
        }
119
    }
120
121
    /**
122
     * Sets the flag if the storage page should be respected for the query.
123
     *
124
     * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
125
     * @return QuerySettingsInterface
126
     */
127
    public function setRespectStoragePage($respectStoragePage)
128
    {
129
        $this->respectStoragePage = $respectStoragePage;
130
        return $this;
131
    }
132
133
    /**
134
     * Returns the state, if the storage page should be respected for the query.
135
     *
136
     * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
137
     */
138
    public function getRespectStoragePage()
139
    {
140
        return $this->respectStoragePage;
141
    }
142
143
    /**
144
     * Sets the pid(s) of the storage page(s) that should be respected for the query.
145
     *
146
     * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
147
     * @return QuerySettingsInterface
148
     */
149
    public function setStoragePageIds(array $storagePageIds)
150
    {
151
        $this->storagePageIds = $storagePageIds;
152
        return $this;
153
    }
154
155
    /**
156
     * Returns the pid(s) of the storage page(s) that should be respected for the query.
157
     *
158
     * @return array list of integers that each represent a storage page id
159
     */
160
    public function getStoragePageIds()
161
    {
162
        return $this->storagePageIds;
163
    }
164
165
    /**
166
     * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
167
     * @return QuerySettingsInterface
168
     */
169
    public function setRespectSysLanguage($respectSysLanguage)
170
    {
171
        $this->respectSysLanguage = $respectSysLanguage;
172
        return $this;
173
    }
174
175
    /**
176
     * @return bool TRUE if TYPO3 language settings are to be applied
177
     */
178
    public function getRespectSysLanguage()
179
    {
180
        return $this->respectSysLanguage;
181
    }
182
183
    /**
184
     * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
185
     * @return QuerySettingsInterface instance of $this to allow method chaining
186
     */
187
    public function setLanguageOverlayMode($languageOverlayMode = false)
188
    {
189
        $this->languageOverlayMode = $languageOverlayMode;
190
        return $this;
191
    }
192
193
    /**
194
     * @return mixed TRUE, FALSE or "hideNonTranslated"
195
     */
196
    public function getLanguageOverlayMode()
197
    {
198
        return $this->languageOverlayMode;
199
    }
200
201
    /**
202
     * Language Mode is NOT used anymore, so just avoid using it. Will be deprecated in the future.
203
     *
204
     * @param string $languageMode
205
     * @return QuerySettingsInterface instance of $this to allow method chaining
206
     * @deprecated since TYPO3 11.0, will be removed in version 12.0
207
     */
208
    public function setLanguageMode($languageMode = '')
209
    {
210
        trigger_error(
211
            __METHOD__ . ' does not have any functionality any more, stop calling it.',
212
            E_USER_DEPRECATED
213
        );
214
        return $this;
215
    }
216
217
    /**
218
     * Language Mode is NOT used anymore, so just avoid using it. Will be deprecated in the future.
219
     *
220
     * @return string NULL, "content_fallback", "strict" or "ignore"
221
     * @deprecated since TYPO3 11.0, will be removed in version 12.0
222
     */
223
    public function getLanguageMode()
224
    {
225
        trigger_error(
226
            __METHOD__ . ' does not have any functionality any more, stop calling it.',
227
            E_USER_DEPRECATED
228
        );
229
        return null;
230
    }
231
232
    /**
233
     * @param int $languageUid
234
     * @return QuerySettingsInterface instance of $this to allow method chaining
235
     */
236
    public function setLanguageUid($languageUid)
237
    {
238
        $this->languageUid = $languageUid;
239
        return $this;
240
    }
241
242
    /**
243
     * @return int
244
     */
245
    public function getLanguageUid()
246
    {
247
        return $this->languageUid;
248
    }
249
250
    /**
251
     * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
252
     * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
253
     * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
254
     *
255
     * @param bool $ignoreEnableFields
256
     * @return QuerySettingsInterface
257
     * @see setEnableFieldsToBeIgnored()
258
     */
259
    public function setIgnoreEnableFields($ignoreEnableFields)
260
    {
261
        $this->ignoreEnableFields = $ignoreEnableFields;
262
        return $this;
263
    }
264
265
    /**
266
     * The returned value indicates whether all or some enable fields should be ignored.
267
     *
268
     * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
269
     * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
270
     *
271
     * @return bool
272
     * @see getEnableFieldsToBeIgnored()
273
     */
274
    public function getIgnoreEnableFields()
275
    {
276
        return $this->ignoreEnableFields;
277
    }
278
279
    /**
280
     * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
281
     * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
282
     * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
283
     *
284
     * @param array $enableFieldsToBeIgnored
285
     * @return QuerySettingsInterface
286
     * @see setIgnoreEnableFields()
287
     */
288
    public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
289
    {
290
        $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
291
        return $this;
292
    }
293
294
    /**
295
     * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
296
     * to be ignored while building the query statement.
297
     *
298
     * @return array
299
     * @see getIgnoreEnableFields()
300
     */
301
    public function getEnableFieldsToBeIgnored()
302
    {
303
        return $this->enableFieldsToBeIgnored;
304
    }
305
306
    /**
307
     * Sets the flag if the query should return objects that are deleted.
308
     *
309
     * @param bool $includeDeleted
310
     * @return QuerySettingsInterface
311
     */
312
    public function setIncludeDeleted($includeDeleted)
313
    {
314
        $this->includeDeleted = $includeDeleted;
315
        return $this;
316
    }
317
318
    /**
319
     * Returns if the query should return objects that are deleted.
320
     *
321
     * @return bool
322
     */
323
    public function getIncludeDeleted()
324
    {
325
        return $this->includeDeleted;
326
    }
327
}
328