/** * Register the loadDataContainer HOOK for the given table name to create the DcGeneral etc. * * @param string $tableName The name of the table to be loaded. * * @param IMetaModelsServiceContainer $container The MetaModels service container. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ private function attachLoadDataContainerHook($tableName, $container) { LoadDataContainerHookListener::attachFor($tableName, function ($tableName) use($container) { $dispatcher = $container->getEventDispatcher(); $event = new LoadDataContainerEvent('tl_metamodel_item'); $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('tl_metamodel_item')); $dispatcher->dispatch(ContaoEvents::CONTROLLER_LOAD_DATA_CONTAINER, $event); if (!isset($GLOBALS['TL_DCA'][$tableName])) { $GLOBALS['TL_DCA'][$tableName] = array(); } $GLOBALS['TL_DCA'][$tableName] = array_replace_recursive((array) $GLOBALS['TL_DCA']['tl_metamodel_item'], (array) $GLOBALS['TL_DCA'][$tableName]); }); }
/** * {@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; }
/** * Create a ICollection instance from the id. * * @param IMetaModel $metaModel The MetaModel for which to retrieve the render setting. * * @param string $settingId The id of the ICollection. * * @return ICollection The instance or null if not found. */ protected function internalCreateRenderSetting(IMetaModel $metaModel, $settingId) { $row = $this->serviceContainer->getDatabase()->prepare('SELECT * FROM tl_metamodel_rendersettings WHERE pid=? AND (id=? OR isdefault=1) ORDER BY isdefault ASC')->limit(1)->execute($metaModel->get('id'), $settingId ?: 0); /** @noinspection PhpUndefinedFieldInspection */ if (!$row->numRows) { $row = null; } $renderSetting = new Collection($metaModel, $row ? $row->row() : array()); if ($renderSetting->get('id')) { $this->collectAttributeSettings($metaModel, $renderSetting); } return $renderSetting; }
/** * {@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()); }
/** * 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); }
/** * Retrieve the Contao database singleton instance. * * @return \Database */ protected function getDatabase() { return $this->container->getDatabase(); }
/** * Retrieve the event dispatcher from the DIC. * * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function getDispatcher() { return $this->container->getEventDispatcher(); }
/** * Parse the defined properties and populate the definition. * * @param IMetaModelDataDefinition $container The data container. * * @return void */ protected function parseProperties(IMetaModelDataDefinition $container) { if ($container->hasPropertiesDefinition()) { $definition = $container->getPropertiesDefinition(); } else { $definition = new DefaultPropertiesDefinition(); $container->setPropertiesDefinition($definition); } $metaModel = $this->getMetaModel(); $inputScreen = $this->getInputScreenDetails(); // If the current metamodels has variants add the varbase and vargroup to the definition. if ($metaModel->hasVariants()) { $this->buildPropertyFromDca($definition, 'varbase', $inputScreen); $this->buildPropertyFromDca($definition, 'vargroup', $inputScreen); } foreach ($metaModel->getAttributes() as $attribute) { $this->buildPropertyFromDca($definition, $attribute->getColName(), $inputScreen); $event = new BuildAttributeEvent($metaModel, $attribute, $container, $inputScreen, $this); // Trigger BuildAttribute Event. $this->serviceContainer->getEventDispatcher()->dispatch($event::NAME, $event); } }