/** * Getting all languages into an array * where the key is the ISO alpha-2 code of the language * and where the value are the name of the language in the current language * Note: we exclude sacred and constructed languages * * @param string additional WHERE clause * @return array An array of names of languages */ public function initLanguages($addWhere = '') { $where = '1=1' . ($addWhere ? ' AND ' . $addWhere : ''); $table = $this->tables['LANGUAGES']; $lang = LocalizationUtility::getCurrentLanguage(); $lang = LocalizationUtility::getIsoLanguageKey($lang); $nameArray = array(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_sacred = 0 AND lg_constructed = 0 ' . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($table)); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $code = $row['lg_iso_2'] . ($row['lg_country_iso_2'] ? '_' . $row['lg_country_iso_2'] : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $row[$titleField]; break; } } } $GLOBALS['TYPO3_DB']->sql_free_result($res); uasort($nameArray, 'strcoll'); return $nameArray; }
$GLOBALS['TCA']['static_languages'] = array('ctrl' => array('label' => 'lg_name_en', 'label_alt' => 'lg_iso_2', 'label_alt_force' => 1, 'label_userFunc' => 'SJBR\\StaticInfoTables\\Hook\\Backend\\Form\\ElementRenderingHelper->addIsoCodeToLabel', 'adminOnly' => 1, 'rootLevel' => 1, 'is_static' => 1, 'readOnly' => 1, 'default_sortby' => 'ORDER BY lg_name_en', 'delete' => 'deleted', 'title' => $extensionResourcesLanguagePath . 'static_languages.title', 'dynamicConfigFile' => $extensionConfigurationTcaPath . 'Language.php', 'iconfile' => $extensionResourcesIconsPath . 'icon_static_languages.gif', 'searchFields' => 'lg_name_en,lg_name_local'), 'interface' => array('showRecordFieldList' => 'lg_name_local,lg_name_en,lg_iso_2,lg_typo3,lg_country_iso_2,lg_collate_locale,lg_sacred,lg_constructed')); // UN Territory reference data $GLOBALS['TCA']['static_territories'] = array('ctrl' => array('label' => 'tr_name_en', 'label_alt' => 'tr_iso_nr', 'label_alt_force' => 1, 'label_userFunc' => 'SJBR\\StaticInfoTables\\Hook\\Backend\\Form\\ElementRenderingHelper->addIsoCodeToLabel', 'adminOnly' => 1, 'rootLevel' => 1, 'is_static' => 1, 'readOnly' => 1, 'default_sortby' => 'ORDER BY tr_name_en', 'delete' => 'deleted', 'title' => $extensionResourcesLanguagePath . 'static_territories.title', 'dynamicConfigFile' => $extensionConfigurationTcaPath . 'Territory.php', 'iconfile' => $extensionResourcesIconsPath . 'icon_static_territories.gif', 'searchFields' => 'tr_name_en'), 'interface' => array('showRecordFieldList' => 'tr_name_en,tr_iso_nr')); unset($extensionResourcesLanguagePath); unset($extensionConfigurationTcaPath); unset($extensionResourcesIconsPath); // Configure static language field of sys_language table if ($typo3Version < 6001000) { \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_language'); } $GLOBALS['TCA']['sys_language']['columns']['static_lang_isocode']['config'] = array('type' => 'select', 'items' => array(array('', 0)), 'foreign_table' => 'static_languages', 'foreign_table_where' => 'AND static_languages.pid=0 ORDER BY static_languages.lg_name_en', 'itemsProcFunc' => 'SJBR\\StaticInfoTables\\Hook\\Backend\\Form\\ElementRenderingHelper->translateLanguagesSelector', 'size' => '1', 'minitems' => '0', 'maxitems' => '1', 'wizards' => array('suggest' => array('type' => 'suggest', 'default' => array('receiverClass' => 'SJBR\\StaticInfoTables\\Hook\\Backend\\Form\\SuggestReceiver')))); if (TYPO3_MODE == 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) { /** * Registers the Static Info Tables Manager backend module, if enabled */ if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['enableManager']) { \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule($_EXTKEY, 'tools', 'Manager', '', array('Manager' => 'information,newLanguagePack,createLanguagePack,testForm,testFormResult,sqlDumpNonLocalizedData'), array('access' => 'user,group', 'icon' => 'EXT:' . $_EXTKEY . '/Resources/Public/Images/Icons/moduleicon.gif', 'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_mod.xlf')); // Add module configuration setup \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY, 'setup', '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/Configuration/TypoScript/Manager/setup.txt">'); // Enable editing Static Info Tables if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables'])) { $tableNames = array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables']); foreach ($tableNames as $tableName) { if ($typo3Version < 6001000) { \SJBR\StaticInfoTables\Utility\TcaUtility::loadTCA($tableName); } $GLOBALS['TCA'][$tableName]['ctrl']['readOnly'] = 0; } } } }
/** * Get the localized value for the label field * * @param array $identifiers An array with key 1- 'uid' containing a uid and/or 2- 'iso' containing one or two iso codes (i.e. country zone code and country code, or language code and country code) * @param string $tableName The name of the table * @param string language ISO code * @param boolean local name only - if set local labels are returned * @return string the value for the label field */ public static function getLabelFieldValue($identifiers, $tableName, $language, $local = FALSE) { $value = ''; $labelFields = self::getLabelFields($tableName, $language, $local); if (count($labelFields)) { // Build the list of fields $prefixedLabelFields = array(); foreach ($labelFields as $labelField) { $prefixedLabelFields[] = $tableName . '.' . $labelField; } $fields = $tableName . '.uid,' . implode(',', $prefixedLabelFields); //Build the where clause $whereClause = ''; if ($identifiers['uid']) { $whereClause .= $tableName . '.uid = ' . intval($identifiers['uid']); } else { if (!empty($identifiers['iso'])) { $isoCode = is_array($identifiers['iso']) ? $identifiers['iso'] : array($identifiers['iso']); foreach ($isoCode as $index => $code) { if ($code) { $field = self::getIsoCodeField($tableName, $code, $index); if ($field) { $whereClause .= ($whereClause ? ' AND ' : '') . $tableName . '.' . $field . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($code, $tableName); } } } } } // Get the entity if ($whereClause) { $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $tableName, $whereClause . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($tableName)); if (is_array($rows) && count($rows)) { foreach ($labelFields as $labelField) { if ($rows[0][$labelField]) { $value = $rows[0][$labelField]; break; } } } } } return $value; }