/**
  * {@inheritdoc}
  */
 public function create($namespace)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $extensions = $this->schemaRegistry->getExtensions($namespace);
     $builder = $this->formFactory->createBuilder('form', null, array('data_class' => null));
     $schema->buildForm($builder);
     foreach ($extensions as $extension) {
         $extension->buildForm($builder);
     }
     return $builder->getForm();
 }
 /**
  * {@inheritdoc}
  *
  * @throws ValidatorException
  */
 public function save($namespace, Settings $settings)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $extensions = $this->schemaRegistry->getExtensions($namespace);
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     foreach ($extensions as $extension) {
         $extension->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])) {
         $this->resolvedSettings[$namespace]->setParameters($parameters);
     }
     $persistedParameters = $this->parameterRepository->findBy(array('namespace' => $namespace));
     $persistedParametersMap = array();
     foreach ($persistedParameters as $parameter) {
         $persistedParametersMap[$parameter->getName()] = $parameter;
     }
     foreach ($parameters as $name => $value) {
         if (isset($persistedParametersMap[$name])) {
             $persistedParametersMap[$name]->setValue($value);
         } else {
             $parameter = $this->parameterRepository->createNew();
             $parameter->setNamespace($namespace)->setName($name)->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->cache->save($namespace, $parameters);
 }