[BUGFIX] Pass language mode to QuerySettings in default language too
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Typo3QuerySettings.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Context\Context;
18 use TYPO3\CMS\Core\Context\LanguageAspect;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21 use TYPO3\CMS\Extbase\Object\ObjectManager;
22 use TYPO3\CMS\Extbase\Service\EnvironmentService;
23
24 /**
25 * Query settings. This class is NOT part of the TYPO3.Flow API.
26 * It reflects the settings unique to TYPO3 CMS.
27 *
28 * @api
29 */
30 class Typo3QuerySettings implements QuerySettingsInterface
31 {
32 /**
33 * Flag if the storage page should be respected for the query.
34 *
35 * @var bool
36 */
37 protected $respectStoragePage = true;
38
39 /**
40 * the pid(s) of the storage page(s) that should be respected for the query.
41 *
42 * @var array
43 */
44 protected $storagePageIds = [];
45
46 /**
47 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
48 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
49 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
50 *
51 * @var bool
52 */
53 protected $ignoreEnableFields = false;
54
55 /**
56 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
57 * to be ignored while building the query statement
58 *
59 * @var array
60 */
61 protected $enableFieldsToBeIgnored = [];
62
63 /**
64 * Flag whether deleted records should be included in the result set.
65 *
66 * @var bool
67 */
68 protected $includeDeleted = false;
69
70 /**
71 * Flag if the sys_language_uid should be respected (default is TRUE).
72 *
73 * @var bool
74 */
75 protected $respectSysLanguage = true;
76
77 /**
78 * Representing sys_language_overlay only valid for current context
79 *
80 * @var mixed
81 */
82 protected $languageOverlayMode = true;
83
84 /**
85 * Representing sys_language_mode only valid for current context
86 *
87 * @var string
88 */
89 protected $languageMode;
90
91 /**
92 * Representing sys_language_uid only valid for current context
93 *
94 * @var int
95 */
96 protected $languageUid = 0;
97
98 /**
99 * @var EnvironmentService
100 */
101 protected $environmentService;
102
103 /**
104 * @param EnvironmentService $environmentService
105 */
106 public function injectEnvironmentService(EnvironmentService $environmentService)
107 {
108 $this->environmentService = $environmentService;
109 }
110
111 /**
112 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
113 * initializeObject is responsible for handling that.
114 */
115 public function initializeObject()
116 {
117 /** @var ObjectManager $objectManager */
118 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
119 /** @var ConfigurationManagerInterface $configurationManager */
120 $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
121 if ($this->environmentService->isEnvironmentInBackendMode() && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
122 $this->setIgnoreEnableFields(true);
123 }
124 /** @var LanguageAspect $languageAspect */
125 $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
126 $this->setLanguageUid($languageAspect->getContentId());
127 $this->setLanguageOverlayMode(false);
128
129 if ($this->environmentService->isEnvironmentInFrontendMode()) {
130 $overlayMode = $languageAspect->getLegacyOverlayType() === 'hideNonTranslated' ? 'hideNonTranslated' : (bool)$languageAspect->getLegacyOverlayType();
131 $this->setLanguageOverlayMode($overlayMode);
132 $this->setLanguageMode($languageAspect->getLegacyLanguageMode() ?: null);
133 } elseif ((int)GeneralUtility::_GP('L')) {
134 // Set language from 'L' parameter
135 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
136 }
137 }
138
139 /**
140 * Sets the flag if the storage page should be respected for the query.
141 *
142 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
143 * @return QuerySettingsInterface
144 * @api
145 */
146 public function setRespectStoragePage($respectStoragePage)
147 {
148 $this->respectStoragePage = $respectStoragePage;
149 return $this;
150 }
151
152 /**
153 * Returns the state, if the storage page should be respected for the query.
154 *
155 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
156 */
157 public function getRespectStoragePage()
158 {
159 return $this->respectStoragePage;
160 }
161
162 /**
163 * Sets the pid(s) of the storage page(s) that should be respected for the query.
164 *
165 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
166 * @return QuerySettingsInterface
167 * @api
168 */
169 public function setStoragePageIds(array $storagePageIds)
170 {
171 $this->storagePageIds = $storagePageIds;
172 return $this;
173 }
174
175 /**
176 * Returns the pid(s) of the storage page(s) that should be respected for the query.
177 *
178 * @return array list of integers that each represent a storage page id
179 */
180 public function getStoragePageIds()
181 {
182 return $this->storagePageIds;
183 }
184
185 /**
186 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
187 * @return QuerySettingsInterface
188 * @api
189 */
190 public function setRespectSysLanguage($respectSysLanguage)
191 {
192 $this->respectSysLanguage = $respectSysLanguage;
193 return $this;
194 }
195
196 /**
197 * @return bool TRUE if TYPO3 language settings are to be applied
198 */
199 public function getRespectSysLanguage()
200 {
201 return $this->respectSysLanguage;
202 }
203
204 /**
205 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
206 * @return QuerySettingsInterface instance of $this to allow method chaining
207 * @api
208 */
209 public function setLanguageOverlayMode($languageOverlayMode = false)
210 {
211 $this->languageOverlayMode = $languageOverlayMode;
212 return $this;
213 }
214
215 /**
216 * @return mixed TRUE, FALSE or "hideNonTranslated"
217 */
218 public function getLanguageOverlayMode()
219 {
220 return $this->languageOverlayMode;
221 }
222
223 /**
224 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
225 * @return QuerySettingsInterface instance of $this to allow method chaining
226 * @api
227 */
228 public function setLanguageMode($languageMode = '')
229 {
230 $this->languageMode = $languageMode;
231 return $this;
232 }
233
234 /**
235 * @return string NULL, "content_fallback", "strict" or "ignore"
236 */
237 public function getLanguageMode()
238 {
239 return $this->languageMode;
240 }
241
242 /**
243 * @param int $languageUid
244 * @return QuerySettingsInterface instance of $this to allow method chaining
245 * @api
246 */
247 public function setLanguageUid($languageUid)
248 {
249 $this->languageUid = $languageUid;
250 return $this;
251 }
252
253 /**
254 * @return int
255 */
256 public function getLanguageUid()
257 {
258 return $this->languageUid;
259 }
260
261 /**
262 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
263 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
264 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
265 *
266 * @param bool $ignoreEnableFields
267 * @return QuerySettingsInterface
268 * @see setEnableFieldsToBeIgnored()
269 * @api
270 */
271 public function setIgnoreEnableFields($ignoreEnableFields)
272 {
273 $this->ignoreEnableFields = $ignoreEnableFields;
274 return $this;
275 }
276
277 /**
278 * The returned value indicates whether all or some enable fields should be ignored.
279 *
280 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
281 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
282 *
283 * @return bool
284 * @see getEnableFieldsToBeIgnored()
285 */
286 public function getIgnoreEnableFields()
287 {
288 return $this->ignoreEnableFields;
289 }
290
291 /**
292 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
293 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
294 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
295 *
296 * @param array $enableFieldsToBeIgnored
297 * @return QuerySettingsInterface
298 * @see setIgnoreEnableFields()
299 * @api
300 */
301 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
302 {
303 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
304 return $this;
305 }
306
307 /**
308 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
309 * to be ignored while building the query statement.
310 *
311 * @return array
312 * @see getIgnoreEnableFields()
313 */
314 public function getEnableFieldsToBeIgnored()
315 {
316 return $this->enableFieldsToBeIgnored;
317 }
318
319 /**
320 * Sets the flag if the query should return objects that are deleted.
321 *
322 * @param bool $includeDeleted
323 * @return QuerySettingsInterface
324 * @api
325 */
326 public function setIncludeDeleted($includeDeleted)
327 {
328 $this->includeDeleted = $includeDeleted;
329 return $this;
330 }
331
332 /**
333 * Returns if the query should return objects that are deleted.
334 *
335 * @return bool
336 */
337 public function getIncludeDeleted()
338 {
339 return $this->includeDeleted;
340 }
341 }