‪TYPO3CMS  9.5
ValuePickerItemDataProvider.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 
22 
28 {
32  protected ‪$siteFinder;
33 
38  public function ‪__construct(‪SiteFinder ‪$siteFinder = null)
39  {
40  $this->siteFinder = ‪$siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class);
41  }
42 
49  public function ‪addData(array $result): array
50  {
51  if ($result['tableName'] === 'sys_redirect' && isset($result['processedTca']['columns']['source_host'])) {
52  $domains = $this->‪getDomains();
53  foreach ($domains as $domain) {
54  $result['processedTca']['columns']['source_host']['config']['valuePicker']['items'][] =
55  [
56  $domain,
57  $domain,
58  ];
59  }
60  }
61  return $result;
62  }
63 
69  protected function ‪getDomains(): array
70  {
71  $domains = $this->‪getDomainsFromAllSites();
72 
73  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_domain');
74  $sysDomainRecords = $queryBuilder
75  ->select('domainName')
76  ->from('sys_domain')
77  ->execute()
78  ->fetchAll();
79  foreach ($sysDomainRecords as $domainRecord) {
80  $domains[] = $domainRecord['domainName'];
81  }
82  $domains = array_unique($domains);
83  sort($domains, SORT_NATURAL);
84  return $domains;
85  }
86 
90  protected function ‪getDomainsFromAllSites(): array
91  {
92  $domains = [];
93  foreach ($this->siteFinder->getAllSites() as $site) {
94  foreach ($site->getAllLanguages() as $language) {
95  $domains[] = $language->getBase()->getHost();
96  }
97  }
98  return $domains;
99  }
100 }
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider\getDomainsFromAllSites
‪array getDomainsFromAllSites()
Definition: ValuePickerItemDataProvider.php:89
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider\getDomains
‪array getDomains()
Definition: ValuePickerItemDataProvider.php:68
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider\addData
‪array addData(array $result)
Definition: ValuePickerItemDataProvider.php:48
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider\$siteFinder
‪SiteFinder $siteFinder
Definition: ValuePickerItemDataProvider.php:31
‪TYPO3\CMS\Redirects\FormDataProvider
Definition: ValuePickerItemDataProvider.php:3
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider
Definition: ValuePickerItemDataProvider.php:28
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:22
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider\__construct
‪__construct(SiteFinder $siteFinder=null)
Definition: ValuePickerItemDataProvider.php:37
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45