/**
  * Parse a single data provider information and prepare the definition object for it.
  *
  * @param ContainerInterface              $container   The container where the data shall be stored.
  *
  * @param DataProviderDefinitionInterface $providers   The data provider container.
  *
  * @param array                           $information The information for the data provider to be parsed.
  *
  * @param string|null                     $name        The name of the data provider to be used within the container.
  *
  * @return ContaoDataProviderInformation|null
  */
 protected function parseSingleDataProvider(ContainerInterface $container, DataProviderDefinitionInterface $providers, array $information, $name)
 {
     if (isset($information['factory'])) {
         $factoryClass = new \ReflectionClass($information['factory']);
         $factory = $factoryClass->newInstance();
         $providerInformation = $factory->build($information);
     } else {
         // Determine the name.
         if ($name && !$this->isSpecialName($name)) {
             $providerName = $name;
         } elseif ($name === 'default') {
             $providerName = $container->getName();
         } elseif (isset($information['source'])) {
             $providerName = $information['source'];
         } else {
             $providerName = $container->getName();
         }
         // Check config if it already exists, if not, add it.
         if (!$providers->hasInformation($providerName)) {
             $providerInformation = new ContaoDataProviderInformation();
             $providerInformation->setName($providerName);
             $providers->addInformation($providerInformation);
         } else {
             $providerInformation = $providers->getInformation($providerName);
         }
         if (!$providerInformation->getTableName()) {
             if (isset($information['source'])) {
                 $providerInformation->setTableName($information['source']);
             } else {
                 $providerInformation->setTableName($providerName);
             }
         }
         if (isset($information['class'])) {
             $providerInformation->setClassName($information['class']);
         }
     }
     return $providerInformation;
 }
 /**
  * This method parses all data provider related information from Contao legacy data container arrays.
  *
  * @param ContainerInterface $container The container where the data shall be stored.
  *
  * @return void
  */
 protected function parseDataProvider(ContainerInterface $container)
 {
     if ($container->hasDataProviderDefinition()) {
         $config = $container->getDataProviderDefinition();
     } else {
         $config = new DefaultDataProviderDefinition();
         $container->setDataProviderDefinition($config);
     }
     // If mode is 5, we need to define tree view.
     if ($this->getFromDca('list/sorting/mode') === 5) {
         if (!$container->getBasicDefinition()->getRootDataProvider()) {
             $container->getBasicDefinition()->setRootDataProvider($container->getName());
         }
     }
     if (($parentTable = $this->getFromDca('config/ptable')) !== null) {
         // Check config if it already exists, if not, add it.
         if (!$config->hasInformation($parentTable)) {
             $providerInformation = new ContaoDataProviderInformation();
             $providerInformation->setName($parentTable);
             $config->addInformation($providerInformation);
         } else {
             $providerInformation = $config->getInformation($parentTable);
         }
         if ($providerInformation instanceof ContaoDataProviderInformation) {
             $initializationData = (array) $providerInformation->getInitializationData();
             $providerInformation->setTableName($parentTable)->setInitializationData(array_merge(array('source' => $parentTable, 'name' => $parentTable), $initializationData));
             if (!$container->getBasicDefinition()->getRootDataProvider()) {
                 $container->getBasicDefinition()->setRootDataProvider($parentTable);
             }
             if (!$container->getBasicDefinition()->getParentDataProvider()) {
                 $container->getBasicDefinition()->setParentDataProvider($parentTable);
             }
         }
     }
     $providerName = $container->getBasicDefinition()->getDataProvider() ?: $container->getName();
     // Check config if it already exists, if not, add it.
     if (!$config->hasInformation($providerName)) {
         $providerInformation = new ContaoDataProviderInformation();
         $providerInformation->setName($providerName);
         $config->addInformation($providerInformation);
     } else {
         $providerInformation = $config->getInformation($providerName);
     }
     if ($providerInformation instanceof ContaoDataProviderInformation) {
         $initializationData = (array) $providerInformation->getInitializationData();
         if (!isset($initializationData['source'])) {
             $providerInformation->setTableName($providerName)->setInitializationData(array_merge(array('source' => $providerName, 'name' => $providerName), $initializationData));
         }
         $providerInformation->setVersioningEnabled((bool) $this->getFromDca('config/enableVersioning'));
         if (!$container->getBasicDefinition()->getDataProvider()) {
             $container->getBasicDefinition()->setDataProvider($providerName);
         }
     }
 }
Esempio n. 3
0
 /**
  * Create the data provider definition in the container if not already set.
  *
  * @param IMetaModelDataDefinition $container The data container.
  *
  * @return void
  */
 protected function parseDataProvider(IMetaModelDataDefinition $container)
 {
     $config = $this->getDataProviderDefinition($container);
     // Check config if it already exists, if not, add it.
     if (!$config->hasInformation($container->getName())) {
         $providerInformation = new ContaoDataProviderInformation();
         $providerInformation->setName($container->getName());
         $config->addInformation($providerInformation);
     } else {
         $providerInformation = $config->getInformation($container->getName());
     }
     if ($providerInformation instanceof ContaoDataProviderInformation) {
         $providerInformation->setTableName($container->getName())->setClassName('MetaModels\\DcGeneral\\Data\\Driver')->setInitializationData(array('source' => $container->getName(), 'service-container' => $this->serviceContainer))->setVersioningEnabled(false);
         $container->getBasicDefinition()->setDataProvider($container->getName());
     }
     // If in hierarchical mode, set the root provider.
     if ($container->getBasicDefinition()->getMode() == BasicDefinitionInterface::MODE_HIERARCHICAL) {
         $container->getBasicDefinition()->setRootDataProvider($container->getName());
     }
     $inputScreen = $this->getInputScreenDetails();
     // If not standalone, set the correct parent provider.
     if (!$inputScreen->isStandalone()) {
         // Check config if it already exists, if not, add it.
         if (!$config->hasInformation($inputScreen->getParentTable())) {
             $providerInformation = new ContaoDataProviderInformation();
             $providerInformation->setName($inputScreen->getParentTable());
             $config->addInformation($providerInformation);
         } else {
             $providerInformation = $config->getInformation($inputScreen->getParentTable());
         }
         if ($providerInformation instanceof ContaoDataProviderInformation) {
             $providerInformation->setTableName($inputScreen->getParentTable())->setInitializationData(array('source' => $inputScreen->getParentTable(), 'service-container' => $this->serviceContainer));
             // How can we honor other drivers? We do only check for MetaModels and legacy SQL here.
             if (in_array($inputScreen->getParentTable(), $this->serviceContainer->getFactory()->collectNames())) {
                 $providerInformation->setClassName('MetaModels\\DcGeneral\\Data\\Driver');
             }
             $container->getBasicDefinition()->setParentDataProvider($inputScreen->getParentTable());
         }
     }
 }