[BUGFIX] Fix foreign_table_where GROUP BY handling
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / DatabasePageLanguageOverlayRows.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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\Backend\Form\FormDataProviderInterface;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
20 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Fill the "pageLanguageOverlayRows" part of the result array
25 */
26 class DatabasePageLanguageOverlayRows implements FormDataProviderInterface
27 {
28 /**
29 * Fetch available page overlay records of page
30 *
31 * @param array $result
32 * @return array
33 */
34 public function addData(array $result)
35 {
36 if ($result['effectivePid'] === 0) {
37 // No overlays for records on pid 0 and not for new pages below root
38 return $result;
39 }
40
41 $result['pageLanguageOverlayRows'] = $this->getDatabaseRows((int)$result['effectivePid']);
42
43 return $result;
44 }
45
46 /**
47 * Retrieve the requested overlay row from the database
48 *
49 * @param int $pid
50 * @return array
51 */
52 protected function getDatabaseRows(int $pid): array
53 {
54 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
55 ->getQueryBuilderForTable('pages_language_overlay');
56 $queryBuilder->getRestrictions()
57 ->removeAll()
58 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
59 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
60
61 $rows = $queryBuilder->select('*')
62 ->from('pages_language_overlay')
63 ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)))
64 ->execute()
65 ->fetchAll();
66
67 return $rows;
68 }
69 }