Пример #1
0
 /**
  * Collect the attribute settings for the given render setting.
  *
  * @param IMetaModel  $metaModel     The MetaModel instance to retrieve the settings for.
  *
  * @param ICollection $renderSetting The render setting.
  *
  * @return void
  */
 public function collectAttributeSettings(IMetaModel $metaModel, $renderSetting)
 {
     $attributeRow = $this->serviceContainer->getDatabase()->prepare('SELECT * FROM tl_metamodel_rendersetting WHERE pid=? AND enabled=1 ORDER BY sorting')->execute($renderSetting->get('id'));
     while ($attributeRow->next()) {
         $attribute = $metaModel->getAttributeById($attributeRow->attr_id);
         if (!$attribute) {
             continue;
         }
         // TODO: we should provide attribute type based render setting elements in version 2.X.
         $attributeSetting = $renderSetting->getSetting($attribute->getColName());
         if (!$attributeSetting) {
             $attributeSetting = $attribute->getDefaultRenderSettings();
         }
         foreach ($attributeRow->row() as $strKey => $varValue) {
             if ($varValue) {
                 $attributeSetting->set($strKey, deserialize($varValue));
             }
         }
         $renderSetting->setSetting($attribute->getColName(), $attributeSetting);
     }
 }
 /**
  * Return all attributes that shall be fetched from the MetaModel.
  *
  * In this base implementation, this only includes the attributes mentioned in the render setting.
  *
  * @author     Christian Schiffler <*****@*****.**>
  * @copyright  The MetaModels team.
  * @see        MetaModels::getAttributeNames
  * @return     string[] the names of the attributes to be fetched.
  */
 protected function getAttributeNames()
 {
     $arrAttributes = $this->renderSetting->getSettingNames();
     // Get the right jumpTo.
     $desiredLanguage = $this->getMetaModel()->getActiveLanguage();
     $strFallbackLanguage = $this->getMetaModel()->getFallbackLanguage();
     $filterSetting = 0;
     foreach ((array) $this->renderSetting->get('jumpTo') as $jumpTo) {
         // If either desired language or fallback, keep the result.
         if (!$this->getMetaModel()->isTranslated() || $jumpTo['langcode'] == $desiredLanguage || $jumpTo['langcode'] == $strFallbackLanguage) {
             $filterSetting = $jumpTo['filter'];
             // If the desired language, break. Otherwise try to get the desired one until all have been evaluated.
             if ($desiredLanguage == $jumpTo['langcode']) {
                 break;
             }
         }
     }
     if ($filterSetting) {
         $objFilterSettings = MetaModelsFilterFactory::byId($filterSetting);
         $arrAttributes = array_merge($objFilterSettings->getReferencedAttributes(), $arrAttributes);
     }
     return $arrAttributes;
 }
Пример #3
0
 /**
  * Retrieve the translation string for the given lang key.
  *
  * In order to achieve the correct caption text, the function tries several translation strings sequentially.
  * The first language key that is set will win, even if it is to be considered empty.
  *
  * This message is looked up in the following order:
  * 1. $GLOBALS['TL_LANG']['MSC'][<mm tablename>][<render settings id>][$langKey]
  * 2. $GLOBALS['TL_LANG']['MSC'][<mm tablename>][$langKey]
  * 3. $GLOBALS['TL_LANG']['MSC'][$langKey]
  *
  * @param string $langKey The language key to retrieve.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 private function getCaptionText($langKey)
 {
     $tableName = $this->getMetaModel()->getTableName();
     if (isset($this->objView) && isset($GLOBALS['TL_LANG']['MSC'][$tableName][$this->objView->get('id')][$langKey])) {
         return $GLOBALS['TL_LANG']['MSC'][$tableName][$this->objView->get('id')][$langKey];
     } elseif (isset($GLOBALS['TL_LANG']['MSC'][$tableName][$langKey])) {
         return $GLOBALS['TL_LANG']['MSC'][$tableName][$langKey];
     }
     return $GLOBALS['TL_LANG']['MSC'][$langKey];
 }
Пример #4
0
 /**
  * Register the assets in Contao.
  *
  * @param ICollection|null $objSettings The render settings to use.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function registerAssets($objSettings)
 {
     if (!$objSettings) {
         return;
     }
     // Include CSS.
     $arrCss = $objSettings->get('additionalCss');
     foreach ((array) $arrCss as $arrFile) {
         if ($arrFile['published']) {
             $GLOBALS['TL_CSS'][md5($arrFile['file'])] = $arrFile['file'];
         }
     }
     // Include JS.
     $arrJs = $objSettings->get('additionalJs');
     foreach ((array) $arrJs as $arrFile) {
         if ($arrFile['published']) {
             $GLOBALS['TL_JAVASCRIPT'][md5($arrFile['file'])] = $arrFile['file'];
         }
     }
 }
 /**
  * Get the defined output format.
  *
  * @param RenderSetting $settings The render settings.
  * @param string        $default  The default output format.
  *
  * @return mixed|null|string
  */
 protected function getOutputFormat(RenderSetting $settings = null, $default = 'text')
 {
     if ($settings) {
         $format = $settings->get('format');
         if (strlen($format)) {
             return $format;
         }
     }
     return $default;
 }