[BUGFIX] Show domains from Site configs in redirect picker
[Packages/TYPO3.CMS.git] / typo3 / sysext / redirects / Classes / FormDataProvider / ValuePickerItemDataProvider.php
index 40a5075..13963f6 100644 (file)
@@ -17,15 +17,28 @@ namespace TYPO3\CMS\Redirects\FormDataProvider;
 
 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
+use TYPO3\CMS\Core\Site\SiteFinder;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
- * Inject sys_domain records into valuepicker form
+ * Inject available domain hosts into a valuepicker form
  * @internal
  */
 class ValuePickerItemDataProvider implements FormDataProviderInterface
 {
+    /**
+     * @var SiteFinder
+     */
+    protected $siteFinder;
+
+    /**
+     * ValuePickerItemDataProvider constructor.
+     * @param SiteFinder|null $siteFinder
+     */
+    public function __construct(SiteFinder $siteFinder = null)
+    {
+        $this->siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class);
+    }
 
     /**
      * Add sys_domains into $result data array
@@ -39,29 +52,49 @@ class ValuePickerItemDataProvider implements FormDataProviderInterface
             $domains = $this->getDomains();
             foreach ($domains as $domain) {
                 $result['processedTca']['columns']['source_host']['config']['valuePicker']['items'][] =
-                [
-                    $domain['domainName'],
-                    $domain['domainName'],
-                ];
+                    [
+                        $domain,
+                        $domain,
+                    ];
             }
         }
         return $result;
     }
 
     /**
-     * Get sys_domain records from database
+     * Get sys_domain records from database, and all from pseudo-sites
      *
      * @return array domain records
      */
-    public function getDomains(): array
+    protected function getDomains(): array
     {
+        $domains = $this->getDomainsFromAllSites();
+
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_domain');
-        $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
-        $domains = $queryBuilder
+        $sysDomainRecords = $queryBuilder
             ->select('domainName')
             ->from('sys_domain')
             ->execute()
             ->fetchAll();
+        foreach ($sysDomainRecords as $domainRecord) {
+            $domains[] = $domainRecord['domainName'];
+        }
+        $domains = array_unique($domains);
+        sort($domains, SORT_NATURAL);
+        return $domains;
+    }
+
+    /**
+     * @return array
+     */
+    protected function getDomainsFromAllSites(): array
+    {
+        $domains = [];
+        foreach ($this->siteFinder->getAllSites() as $site) {
+            foreach ($site->getAllLanguages() as $language) {
+                $domains[] = $language->getBase()->getHost();
+            }
+        }
         return $domains;
     }
 }