Passed
Push — master ( a7d46b...0a8eff )
by
unknown
14:11
created

Typo3QuerySettings::initializeObject()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
rs 8.4444
c 0
b 0
f 0
cc 8
nc 8
nop 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
use TYPO3\CMS\Extbase\Object\ObjectManager;
25
26
/**
27
 * Query settings, reflects the settings unique to TYPO3 CMS.
28
 */
29
class Typo3QuerySettings implements QuerySettingsInterface
30
{
31
    /**
32
     * Flag if the storage page should be respected for the query.
33
     *
34
     * @var bool
35
     */
36
    protected $respectStoragePage = true;
37
38
    /**
39
     * the pid(s) of the storage page(s) that should be respected for the query.
40
     *
41
     * @var array
42
     */
43
    protected $storagePageIds = [];
44
45
    /**
46
     * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
47
     * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
48
     * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
49
     *
50
     * @var bool
51
     */
52
    protected $ignoreEnableFields = false;
53
54
    /**
55
     * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
56
     * to be ignored while building the query statement
57
     *
58
     * @var array
59
     */
60
    protected $enableFieldsToBeIgnored = [];
61
62
    /**
63
     * Flag whether deleted records should be included in the result set.
64
     *
65
     * @var bool
66
     */
67
    protected $includeDeleted = false;
68
69
    /**
70
     * Flag if the sys_language_uid should be respected (default is TRUE).
71
     *
72
     * @var bool
73
     */
74
    protected $respectSysLanguage = true;
75
76
    /**
77
     * Representing sys_language_overlay only valid for current context
78
     *
79
     * @var bool
80
     */
81
    protected $languageOverlayMode = true;
82
83
    /**
84
     * Representing sys_language_uid only valid for current context
85
     *
86
     * @var int
87
     */
88
    protected $languageUid = 0;
89
90
    /**
91
     * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
92
     * initializeObject is responsible for handling that.
93
     */
94
    public function initializeObject()
95
    {
96
        /** @var ObjectManager $objectManager */
97
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
98
        /** @var ConfigurationManagerInterface $configurationManager */
99
        $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
100
        if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
101
            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
102
            && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
103
            $this->setIgnoreEnableFields(true);
104
        }
105
        /** @var LanguageAspect $languageAspect */
106
        $languageAspect = GeneralUtility::makeInstance(Context::class)->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