Beispiel #1
0
 /**
  * Determine the page id and other details.
  *
  * @return array
  */
 private function determineJumpToInformation()
 {
     // Get the right jumpto.
     $translated = $this->metaModel->isTranslated();
     $desiredLanguage = $this->metaModel->getActiveLanguage();
     $fallbackLanguage = $this->metaModel->getFallbackLanguage();
     $jumpToPageId = '';
     $filterSettingId = '';
     if (!isset($this->jumpToCache[$desiredLanguage . '.' . $fallbackLanguage])) {
         $serviceContainer = $this->metaModel->getServiceContainer();
         foreach ((array) $this->get('jumpTo') as $jumpTo) {
             $langCode = $jumpTo['langcode'];
             // If either desired language or fallback, keep the result.
             if (!$translated || $langCode == $desiredLanguage || $langCode == $fallbackLanguage) {
                 $jumpToPageId = $jumpTo['value'];
                 $filterSettingId = $jumpTo['filter'];
                 // If the desired language, break.
                 // Otherwise try to get the desired one until all have been evaluated.
                 if ($desiredLanguage == $jumpTo['langcode']) {
                     break;
                 }
             }
         }
         $pageDetails = $this->getPageDetails($jumpToPageId);
         $filterSetting = $filterSettingId ? $serviceContainer->getFilterFactory()->createCollection($filterSettingId) : null;
         $this->jumpToCache[$desiredLanguage . '.' . $fallbackLanguage] = array('page' => $jumpToPageId, 'pageDetails' => $pageDetails, 'filter' => $filterSettingId, 'filterSetting' => $filterSetting, 'language' => $pageDetails['language'], 'label' => $this->getJumpToLabel());
     }
     return $this->jumpToCache[$desiredLanguage . '.' . $fallbackLanguage];
 }
Beispiel #2
0
 /**
  * Get the language.
  *
  * First check the overwrite language. Then check if the MetaModels is translated and get all languages from it.
  * Use the current language as fallback.
  *
  * @param string     $singleLanguage The language with the overwrite.
  *
  * @param IMetaModel $metaModels     The MetaModels for the check.
  *
  * @return string[] A list with all languages or null.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function getLanguage($singleLanguage, $metaModels)
 {
     if (!empty($singleLanguage)) {
         return array($singleLanguage);
     } elseif ($metaModels->isTranslated() && $metaModels->getAvailableLanguages()) {
         return $metaModels->getAvailableLanguages();
     }
     return array($GLOBALS['TL_LANGUAGE']);
 }
Beispiel #3
0
 /**
  * Create a widget for naming contexts. Use the language and translation information from the MetaModel.
  *
  * @param EnvironmentInterface $environment   The environment.
  *
  * @param PropertyInterface    $property      The property.
  *
  * @param IMetaModel           $metaModel     The MetaModel.
  *
  * @param string               $languageLabel The label to use for the language indicator.
  *
  * @param string               $valueLabel    The label to use for the input field.
  *
  * @param bool                 $isTextArea    If true, the widget will become a textarea, false otherwise.
  *
  * @param array                $arrValues     The values for the widget, needed to highlight the fallback language.
  *
  * @return void
  */
 public static function prepareLanguageAwareWidget(EnvironmentInterface $environment, PropertyInterface $property, IMetaModel $metaModel, $languageLabel, $valueLabel, $isTextArea, $arrValues)
 {
     if (!$metaModel->isTranslated()) {
         $extra = $property->getExtra();
         $extra['tl_class'] .= 'w50';
         $property->setWidgetType('text')->setExtra($extra);
         return;
     }
     $fallback = $metaModel->getFallbackLanguage();
     $languages = self::buildLanguageArray($metaModel, $environment->getTranslator());
     $neededKeys = array_keys($languages);
     // Ensure we have values for all languages present.
     if (array_diff_key(array_keys($arrValues), $neededKeys)) {
         foreach ($neededKeys as $langCode) {
             $arrValues[$langCode] = '';
         }
     }
     $rowClasses = array();
     foreach (array_keys($arrValues) as $langCode) {
         $rowClasses[] = $langCode == $fallback ? 'fallback_language' : 'normal_language';
     }
     $extra = $property->getExtra();
     $extra['minCount'] = $extra['maxCount'] = count($languages);
     $extra['disableSorting'] = true;
     $extra['tl_class'] = 'clr';
     $extra['columnFields'] = array('langcode' => array('label' => $languageLabel, 'exclude' => true, 'inputType' => 'justtextoption', 'options' => $languages, 'eval' => array('rowClasses' => $rowClasses, 'valign' => 'center', 'style' => 'min-width:75px;display:block;')), 'value' => array('label' => $valueLabel, 'exclude' => true, 'inputType' => $isTextArea ? 'textarea' : 'text', 'eval' => array('rowClasses' => $rowClasses, 'style' => 'width:400px;', 'rows' => 3)));
     $property->setWidgetType('multiColumnWizard')->setExtra($extra);
 }
 /**
  * Get available langauges.
  *
  * @param IMetaModel $objMetaModel The metamodel.
  *
  * @return array|null|\string[]
  */
 private function getAvailableLanguages(IMetaModel $objMetaModel)
 {
     return $objMetaModel->isTranslated() && $this->get('all_langs') ? $objMetaModel->getAvailableLanguages() : array($objMetaModel->getActiveLanguage());
 }