[!!!][TASK] Deprecate FormEngine::getAvailableLanguages() 92/35492/2
authorFrank Nägler <typo3@naegler.net>
Mon, 15 Dec 2014 18:25:31 +0000 (19:25 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Mon, 15 Dec 2014 18:42:08 +0000 (19:42 +0100)
This patch deprecates FormEngine::getAvailableLanguages()
and removes the dependency from all form element classes.

Resolves: #63852
Releases: master
Change-Id: I3173ea36d741d06ad8b0d6df226193079395d106
Reviewed-on: http://review.typo3.org/35492
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Form/Element/FlexElement.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-63852-FormEngine-getAvailableLanguages.rst [new file with mode: 0644]

index 792a5e2..852bb1b 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\Form\Element;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -74,7 +75,7 @@ class FlexElement extends AbstractFormElement {
                                        . BackendUtility::versioningPlaceholderClause('pages_language_overlay');
                                $pageOverlays = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'pages_language_overlay', $where_clause, '', '', '', 'sys_language_uid');
                        }
-                       $languages = $this->formEngine->getAvailableLanguages();
+                       $languages = $this->getAvailableLanguages();
                        foreach ($languages as $lInfo) {
                                if (
                                        $this->getBackendUserAuthentication()->checkLanguageAccess($lInfo['uid'])
@@ -203,6 +204,45 @@ class FlexElement extends AbstractFormElement {
                return $item;
        }
 
+       /**
+        * Returns an array of available languages (to use for FlexForms)
+        *
+        * @param bool $onlyIsoCoded If set, only languages which are paired with a static_info_table / static_language record will be returned.
+        * @param bool $setDefault If set, an array entry for a default language is set.
+        * @return array
+        */
+       protected function getAvailableLanguages($onlyIsoCoded = TRUE, $setDefault = TRUE) {
+               $isL = ExtensionManagementUtility::isLoaded('static_info_tables');
+               // Find all language records in the system:
+               $db = $this->getDatabaseConnection();
+               $res = $db->exec_SELECTquery('language_isocode,static_lang_isocode,title,uid', 'sys_language', 'pid=0 AND hidden=0' . BackendUtility::deleteClause('sys_language'), '', 'title');
+               // Traverse them:
+               $output = array();
+               if ($setDefault) {
+                       $output[0] = array(
+                               'uid' => 0,
+                               'title' => 'Default language',
+                               'ISOcode' => 'DEF'
+                       );
+               }
+               while ($row = $db->sql_fetch_assoc($res)) {
+                       $output[$row['uid']] = $row;
+                       if (!empty($row['language_isocode'])) {
+                               $output[$row['uid']]['ISOcode'] = $row['language_isocode'];
+                       } elseif ($isL && $row['static_lang_isocode']) {
+                               GeneralUtility::deprecationLog('Usage of the field "static_lang_isocode" is discouraged, and will stop working with CMS 8. Use the built-in language field "language_isocode" in your sys_language records.');
+                               $rr = BackendUtility::getRecord('static_languages', $row['static_lang_isocode'], 'lg_iso_2');
+                               if ($rr['lg_iso_2']) {
+                                       $output[$row['uid']]['ISOcode'] = $rr['lg_iso_2'];
+                               }
+                       }
+                       if ($onlyIsoCoded && !$output[$row['uid']]['ISOcode']) {
+                               unset($output[$row['uid']]);
+                       }
+               }
+               $db->sql_free_result($res);
+               return $output;
+       }
 
        /**
         * Recursive rendering of flexforms
index 1e340ad..5aafcd1 100644 (file)
@@ -4312,8 +4312,10 @@ class FormEngine {
         * @param bool $onlyIsoCoded If set, only languages which are paired with a static_info_table / static_language record will be returned.
         * @param bool $setDefault If set, an array entry for a default language is set.
         * @return array
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
         */
        public function getAvailableLanguages($onlyIsoCoded = TRUE, $setDefault = TRUE) {
+               GeneralUtility::logDeprecatedFunction();
                $isL = ExtensionManagementUtility::isLoaded('static_info_tables');
                // Find all language records in the system:
                $db = $this->getDatabaseConnection();
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-63852-FormEngine-getAvailableLanguages.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-63852-FormEngine-getAvailableLanguages.rst
new file mode 100644 (file)
index 0000000..5c906fe
--- /dev/null
@@ -0,0 +1,24 @@
+===================================================================
+Deprecation: #63852 - Deprecate FormEngine::getAvailableLanguages()
+===================================================================
+
+Description
+===========
+
+:php:`FormEngine::getAvailableLanguages()` has been deprecated.
+
+
+Impact
+======
+
+Using :php:`getAvailableLanguages()` of FormEngine class will trigger a deprecation log message.
+
+Affected installations
+======================
+
+Instances which use custom form elements, which make use of :php:`FormEngine::getAvailableLanguages()`.
+
+Migration
+=========
+
+No migration possible.