/** * {@inheritDoc} * * @throws \RuntimeException When the instance could not be retrieved. */ public function getMetaModel() { $factory = $this->container->getFactory(); $metaModel = $factory->getMetaModel($factory->translateIdToMetaModelName($this->data['pid'])); if ($metaModel === null) { throw new \RuntimeException('Could not retrieve MetaModel with id ' . $this->data['pid']); } return $metaModel; }
/** * {@inheritdoc} * * @throws \RuntimeException When the MetaModel could not be retrieved. */ public function createCollection($settingId) { // TODO: we should provide a collector like for attributes. $information = $this->serviceContainer->getDatabase()->prepare('SELECT * FROM tl_metamodel_filter WHERE id=?')->execute($settingId)->row(); if (!empty($information)) { $modelFactory = $this->serviceContainer->getFactory(); $metaModel = $modelFactory->getMetaModel($modelFactory->translateIdToMetaModelName($information['pid'])); $collection = new Collection($information); if ($metaModel === null) { throw new \RuntimeException('Could not retrieve MetaModel ' . $information['pid']); } $collection->setMetaModel($metaModel); $this->collectRules($collection); return $collection; } return new Collection(array()); }
/** * Resolve all combinations available. * * @return void */ protected function resolve() { $factory = $this->container->getFactory(); $names = $factory->collectNames(); foreach ($names as $name) { $this->information[$name] = array(self::COMBINATION => null, self::INPUTSCREEN => null, self::RENDERSETTING => null, self::MODELID => null); } $found = $this->getPaletteCombinationRows(); if (!$found) { $found = array(); } $this->getPaletteCombinationDefault($found); // Clean any undefined. foreach (array_keys($this->information) as $tableName) { if (empty($this->information[$tableName][self::COMBINATION]) || empty($this->information[$tableName][self::COMBINATION]['dca_id']) || empty($this->information[$tableName][self::COMBINATION]['view_id'])) { unset($this->information[$tableName]); } } $this->fetchInputScreenDetails(); }
/** * Retrieve the MetaModel with the given id. * * @param int $modelId The model being processed. * * @return IMetaModel */ private function getMetaModelById($modelId) { $modelFactory = $this->serviceContainer->getFactory(); $name = $modelFactory->translateIdToMetaModelName($modelId); return $modelFactory->getMetaModel($name); }
/** * Parse the listing configuration. * * @param IMetaModelDataDefinition $container The data container. * * @param Contao2BackendViewDefinitionInterface $view The view definition. * * @return void */ protected function parseListing(IMetaModelDataDefinition $container, Contao2BackendViewDefinitionInterface $view) { $listing = $view->getListingConfig(); if ($listing->getRootLabel() === null) { $listing->setRootLabel($this->getMetaModel()->get('name')); } if ($listing->getRootIcon() === null && ($inputScreen = $this->getInputScreenDetails()) !== null) { $icon = ToolboxFile::convertValueToPath($inputScreen->getIcon()); // Determine image to use. if ($icon && file_exists(TL_ROOT . '/' . $icon)) { $event = new ResizeImageEvent($icon, 16, 16); $this->serviceContainer->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_RESIZE, $event); $icon = $event->getResultImage(); } else { $icon = 'system/modules/metamodels/assets/images/icons/metamodels.png'; } $listing->setRootIcon($icon); } $this->parseListSorting($listing); $this->parseListLabel($container, $listing); if ($inputScreen = $this->getInputScreenDetails()) { $listing->setShowColumns($inputScreen->isShowColumns()); $renderSetting = $this->serviceContainer->getService('metamodels-view-combinations')->getRenderSetting($container->getName()); $metaModel = $this->serviceContainer->getFactory()->getMetaModel($container->getName()); /** @var $renderSettingCollection \MetaModels\Render\Setting\Collection */ $renderSettingCollection = $this->serviceContainer->getRenderSettingFactory()->createCollection($metaModel, $renderSetting); $listing->getLabelFormatter($container->getName())->setPropertyNames($renderSettingCollection->getSettingNames()); } }