/**
  * Create the edit mask.
  *
  * @param EnvironmentInterface $environment   The view in use.
  *
  * @param ModelInterface       $model         The model with the current data.
  *
  * @param ModelInterface       $originalModel The data from the original data.
  *
  * @param callable             $preFunction   The function to call before saving an item.
  *
  * @param callable             $postFunction  The function to call after saving an item.
  */
 public function __construct($environment, $model, $originalModel, $preFunction, $postFunction)
 {
     $providerName = $model->getProviderName();
     $this->environment = $environment;
     $this->translator = $environment->getTranslator();
     $this->dispatcher = $environment->getEventDispatcher();
     $this->definition = $environment->getDataDefinition();
     $this->modelProvider = $this->definition->getDataProviderDefinition()->getInformation($providerName);
     $this->model = $model;
     $this->originalModel = $originalModel;
     $this->preFunction = $preFunction;
     $this->postFunction = $postFunction;
 }
 /**
  * Determine the root provider name from the container.
  *
  * @param ContainerInterface $container The container from where the name shall be retrieved.
  *
  * @return string
  *
  * @throws DcGeneralRuntimeException If the root provider can not be determined.
  */
 protected function getRootProviderName(ContainerInterface $container)
 {
     $rootProvider = $container->getBasicDefinition()->getRootDataProvider();
     if (!$rootProvider) {
         throw new DcGeneralRuntimeException('Root data provider name not specified in DCA but rootEntries section specified.');
     }
     if (!$container->getDataProviderDefinition()->hasInformation($rootProvider)) {
         throw new DcGeneralRuntimeException('Unknown root data provider but rootEntries section specified.');
     }
     return $rootProvider;
 }
 /**
  * Parse the root condition.
  *
  * @param ContainerInterface                   $container  The container where the data shall be stored.
  *
  * @param ModelRelationshipDefinitionInterface $definition The relationship definition.
  *
  * @return void
  *
  * @throws DcGeneralRuntimeException If no root data provider is defined.
  */
 protected function parseRootCondition(ContainerInterface $container, ModelRelationshipDefinitionInterface $definition)
 {
     if (($rootCondition = $this->getFromDca('dca_config/rootEntries')) !== null) {
         $rootProvider = $container->getBasicDefinition()->getRootDataProvider();
         if (!$rootProvider) {
             throw new DcGeneralRuntimeException('Root data provider name not specified in DCA but rootEntries section specified.');
         }
         if (!$container->getDataProviderDefinition()->hasInformation($rootProvider)) {
             throw new DcGeneralRuntimeException('Unknown root data provider but rootEntries section specified.');
         }
         if (isset($rootCondition[$rootProvider])) {
             $rootCondition = $rootCondition[$rootProvider];
             $mySetter = $rootCondition['setOn'];
             if (($relationship = $definition->getRootCondition()) === null) {
                 $relationship = new RootCondition();
                 $setter = $mySetter;
                 $builder = FilterBuilder::fromArrayForRoot()->getFilter();
             } else {
                 /** @var RootConditionInterface $relationship */
                 if ($relationship->getSetters()) {
                     $setter = array_merge_recursive($mySetter, $relationship->getSetters());
                 } else {
                     $setter = $mySetter;
                 }
                 $builder = FilterBuilder::fromArrayForRoot($relationship->getFilterArray())->getFilter();
             }
             $builder->append(FilterBuilder::fromArrayForRoot((array) $rootCondition['filter']));
             $relationship->setSourceName($rootProvider)->setFilterArray($builder->getAllAsArray())->setSetters($setter);
             $definition->setRootCondition($relationship);
         }
     }
 }