public function register(Container $container)
 {
     $container['simpleform.config.path'] = '';
     $container['simpleform.config.cache_path'] = '';
     $container['simpleform.config.class'] = 'PhpGo\\SimpleAdminBundle\\Form\\Config';
     $container['simpleform.forms.class'] = 'PhpGo\\SimpleAdminBundle\\Form\\Forms';
     $container['simpleform.custom_fields'] = [];
     $container['form.types'] = function () {
         return [new StringType()];
     };
     $container['simpleform.config'] = function (Container $container) {
         //            $coreFieldsNamespace = 'PhpGo\\SimpleAdminBundle\\Form\\Field\\';
         $coreFields = ['PhpGo\\SimpleAdminBundle\\Form\\Field\\StringField'];
         Forms::registerFields($coreFields);
         Forms::registerFields($container['simpleform.custom_fields']);
         $container->extend('form.types', function ($types, $container) {
             /** @var FieldAbstract $field */
             foreach ($container['simpleform.custom_fields'] as $field) {
                 if ($type = $field::getType()) {
                     $types[] = $type;
                 }
             }
             return $types;
         });
         $config = $container['simpleform.config.class']::createFromYaml($container['simpleform.config.path']);
         return $config;
     };
     $container['forms'] = function ($container) {
         /** @var Forms $forms */
         $forms = new $container['simpleform.forms.class']($container['simpleform.config'], $container['form.factory']);
         return $forms;
     };
 }
Esempio n. 2
0
 public static function createFromConfig($name, Config $config)
 {
     $form = new static();
     $form->setName($name);
     $form->setConfig($config);
     foreach ($form->getConfig()['form'] as $name => $field) {
         $newField = Forms::createField($field['type']);
         $newField->setName($name);
         $options = [];
         $options['label'] = isset($field['label']) ? $field['label'] : $name;
         if (isset($field['options'])) {
             $options = array_merge($options, $field['options']);
         }
         $newField->setOptions($options);
         $form->addField($newField);
     }
     return $form;
 }