40a5075319689acc67c6e59a1b8f9532935340c0
[Packages/TYPO3.CMS.git] / typo3 / sysext / redirects / Classes / FormDataProvider / ValuePickerItemDataProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Redirects\FormDataProvider;
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
18 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Inject sys_domain records into valuepicker form
25 * @internal
26 */
27 class ValuePickerItemDataProvider implements FormDataProviderInterface
28 {
29
30 /**
31 * Add sys_domains into $result data array
32 *
33 * @param array $result Initialized result array
34 * @return array Result filled with more data
35 */
36 public function addData(array $result): array
37 {
38 if ($result['tableName'] === 'sys_redirect' && isset($result['processedTca']['columns']['source_host'])) {
39 $domains = $this->getDomains();
40 foreach ($domains as $domain) {
41 $result['processedTca']['columns']['source_host']['config']['valuePicker']['items'][] =
42 [
43 $domain['domainName'],
44 $domain['domainName'],
45 ];
46 }
47 }
48 return $result;
49 }
50
51 /**
52 * Get sys_domain records from database
53 *
54 * @return array domain records
55 */
56 public function getDomains(): array
57 {
58 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_domain');
59 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
60 $domains = $queryBuilder
61 ->select('domainName')
62 ->from('sys_domain')
63 ->execute()
64 ->fetchAll();
65 return $domains;
66 }
67 }