Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function create($namespace)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $builder = $this->formFactory->createBuilder('form', null, array('data_class' => null));
     $schema->buildForm($builder);
     return $builder->getForm();
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function create($namespace, $data = null, array $options = [])
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
     $schema->buildForm($builder);
     return $builder->getForm();
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  * @throws ValidatorException
  */
 public function saveSettings($namespace, Settings $settings)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     $parameters = $settingsBuilder->resolve($settings->getParameters());
     foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
         if (array_key_exists($parameter, $parameters)) {
             $parameters[$parameter] = $transformer->transform($parameters[$parameter]);
         }
     }
     if (isset($this->resolvedSettings[$namespace])) {
         $transformedParameters = $this->transformParameters($settingsBuilder, $parameters);
         $this->resolvedSettings[$namespace]->setParameters($transformedParameters);
     }
     $persistedParameters = $this->parameterRepository->findBy(array('namespace' => $namespace));
     $persistedParametersMap = array();
     foreach ($persistedParameters as $parameter) {
         $persistedParametersMap[$parameter->getName()] = $parameter;
     }
     $this->eventDispatcher->dispatch(SettingsEvent::PRE_SAVE, new SettingsEvent($namespace, $settings, $parameters));
     foreach ($parameters as $name => $value) {
         if (isset($persistedParametersMap[$name])) {
             $persistedParametersMap[$name]->setValue($value);
         } else {
             $parameter = $this->parameterRepository->createNew();
             $parameter->setNamespace($namespace);
             $parameter->setName($name);
             $parameter->setValue($value);
             /* @var $errors ConstraintViolationListInterface */
             $errors = $this->validator->validate($parameter);
             if (0 < $errors->count()) {
                 throw new ValidatorException($errors->get(0)->getMessage());
             }
             $this->parameterManager->persist($parameter);
         }
     }
     $this->parameterManager->flush();
     $this->eventDispatcher->dispatch(SettingsEvent::POST_SAVE, new SettingsEvent($namespace, $settings, $parameters));
     $this->cache->save($namespace, $parameters);
 }