/**
  * @param CreateProviderEvent $event
  */
 public function createProvider(CreateProviderEvent $event)
 {
     $model = $event->getProviderModel();
     if ($model->type != 'metamodels') {
         return;
     }
     $metaModel = MetaModelsFactory::byId($model->mm_metamodel);
     // metamodel does not exists. break it here
     if (!$metaModel) {
         return;
     }
     $provider = MetaModelsProvider::create($metaModel, $model->id)->setParent($model->mm_parent_type, $model->mm_parent_page);
     $attributeMappings = deserialize($model->mm_attributes, true);
     foreach ($attributeMappings as $config) {
         if ($config['id'] && $config['html']) {
             $provider->addAttributeMapping($config['id'], $config['html'], $config['type'], $config['format']);
         }
     }
     if ($model->mm_filter) {
         $filter = MetaModelsFilterFactory::byId($model->mm_filter);
         $params = $this->createFilterParams($filter);
         if ($filter) {
             $provider->setFilter($filter, $params);
         }
     }
     if ($model->mm_render_setting) {
         $renderSetting = Factory::byId($metaModel, $model->mm_render_setting);
         $provider->setRenderSetting($renderSetting);
     }
     if ($model->mm_sort_by) {
         $provider->setSorting($model->mm_sort_by, $model->mm_sort_direction ?: 'ASC');
     }
     $event->setProvider($provider);
 }
 /**
  * Get all MetaModel items.
  *
  * @param MetaModel  $metaModel The MetaModel.
  * @param LayerModel $model     The layer model.
  * @param Filter     $filter    Optional request filter.
  *
  * @return Items
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 private function getItems(MetaModel $metaModel, LayerModel $model, Filter $filter = null)
 {
     $metaModelFilter = $metaModel->getEmptyFilter();
     $filterSetting = FilterSettingFactory::byId($model->metamodel_filtering);
     $filterSetting->addRules($metaModelFilter, array_merge(deserialize($model->metamodel_filteraprams, true), $this->getFilterParameters($filterSetting)));
     return $metaModel->findByFilter($metaModelFilter, $model->metamodel_sortby, 0, $model->metamodel_use_limit ? $model->metamodel_limit ?: 0 : 0, $model->metamodel_sortby_direction);
 }
 /**
  * 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;
 }