[!!!][TASK] Remove sys_domain and LegacyDomains
[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\Site\SiteFinder;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Inject available domain hosts into a valuepicker form
24 * @internal
25 */
26 class ValuePickerItemDataProvider implements FormDataProviderInterface
27 {
28 /**
29 * @var SiteFinder
30 */
31 protected $siteFinder;
32
33 /**
34 * ValuePickerItemDataProvider constructor.
35 * @param SiteFinder|null $siteFinder
36 */
37 public function __construct(SiteFinder $siteFinder = null)
38 {
39 $this->siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class);
40 }
41
42 /**
43 * Add sys_domains into $result data array
44 *
45 * @param array $result Initialized result array
46 * @return array Result filled with more data
47 */
48 public function addData(array $result): array
49 {
50 if ($result['tableName'] === 'sys_redirect' && isset($result['processedTca']['columns']['source_host'])) {
51 $domains = $this->getHosts();
52 foreach ($domains as $domain) {
53 $result['processedTca']['columns']['source_host']['config']['valuePicker']['items'][] =
54 [
55 $domain,
56 $domain,
57 ];
58 }
59 }
60 return $result;
61 }
62
63 /**
64 * Get all hosts from sites
65 *
66 * @return array domain records
67 */
68 protected function getHosts(): array
69 {
70 $domains = [];
71 foreach ($this->siteFinder->getAllSites() as $site) {
72 foreach ($site->getAllLanguages() as $language) {
73 $domains[] = $language->getBase()->getHost();
74 }
75 }
76 $domains = array_unique($domains);
77 sort($domains, SORT_NATURAL);
78 return $domains;
79 }
80 }