示例#1
0
 public function compileForm($action, $parent_builder, $admin, $object, \Symforce\AdminBundle\Compiler\MetaType\PropertyContainer $property_container, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer, $parent_property = null)
 {
     $this_builder = $parent_builder . '_' . $this->id;
     $options = array("sf_form_type" => "sf_group", "label" => $this->label->getPhpCode());
     if ($this->show_on) {
         if (!is_array($this->show_on)) {
             $this->throwError("show_on need be array, you set %s", gettype($this->show_on));
         }
         $_or = $this->show_on;
         if (!\Dev::isSimpleArray($this->show_on)) {
             $_or = array($_or);
         }
         $options['sf_form_dynamic'] = $_or;
     }
     $writer->write($this_builder . ' = $builder->create("sf_form_group_' . $this->id . '", "sf_group", ')->write(var_export($options, 1))->writeln(');');
     foreach ($this->properties as $property_name) {
         if (!$property_container->hasProperty($property_name)) {
             continue;
         }
         $element = $property_container->properties[$property_name];
         $element->compileActionForm($action, $this_builder, $admin, $object, $parent_property);
     }
     $writer->writeln(sprintf('if( %s->count() > 0 ) { ', $this_builder))->indent()->writeln($parent_builder . '->add(' . $this_builder . ');')->outdent()->writeln("}");
 }
示例#2
0
 public function lazyInitialize()
 {
     if ($this->lazy_initialized) {
         throw new \Exception('big error');
     }
     $this->lazy_initialized = true;
     $this->tr_node = $this->admin_object->tr_node->getNodeByPath('form');
     $this->children->tr_node = $this->tr_node;
     foreach ($this->lazy_children as $property => &$annotations) {
         $embed = null;
         if ($this->children->hasProperty($property)) {
             $embed = $this->children->getProperty($property);
             if ('sf_embed' !== $embed->compile_form_type) {
                 $this->throwError("property:%s form type must be `embed',  you use:`%s`", $property, $embed->compile_form_type);
             }
         } else {
             $embed = new \Symforce\AdminBundle\Compiler\MetaType\Form\Embed($this, $property);
         }
         foreach ($annotations as $parent_class => &$properties) {
             if (null !== $embed->children) {
                 // , $embed->children->admin_object->class_name, $parent_class
                 $this->throwError("should map to one class for each property");
             }
             $admin = $this->admin_object->generator->getAdminByClass($parent_class);
             $cache = $this->admin_object->generator->getAnnotationCache($parent_class);
             $embed->children = new \Symforce\AdminBundle\Compiler\MetaType\PropertyContainer($this, $admin);
             foreach ($properties as $parent_property => $annot) {
                 $copy_annot = false;
                 if (isset($cache->propertie_annotations[$parent_property][self::FORM_ANNOT_CLASS])) {
                     $_annot = $cache->propertie_annotations[$parent_property][self::FORM_ANNOT_CLASS];
                     foreach ($_annot as $key => $value) {
                         if (null !== $value && $value !== $annot->{$key}) {
                             $annot->{$key} = $value;
                             $copy_annot = true;
                         }
                     }
                     if (0 && $copy_annot) {
                         throw new \Exception("not implement copy form yet!");
                         exit;
                     }
                     $sub_element = $this->admin_object->generator->form_factory->create($parent_class, $parent_property, $annot, $embed->children, $admin);
                 } else {
                     $sub_element = $this->admin_object->generator->form_factory->create($parent_class, $parent_property, $annot, $embed->children, $admin);
                 }
             }
         }
     }
     foreach ($this->children->properties as $property) {
         $property->lazyInitialize();
     }
     if (!isset($this->groups['default'])) {
         $this->groups['default'] = new \Symforce\AdminBundle\Compiler\MetaType\Form\Group('default');
     }
     foreach ($this->children->properties as $field) {
         if (!$field->group) {
             $this->groups['default']->add($field->class_property, $field->position);
         } else {
             if (!isset($this->groups[$field->group])) {
                 $this->groups[$field->group] = new \Symforce\AdminBundle\Compiler\MetaType\Form\Group($field->group);
             }
             $this->groups[$field->group]->add($field->class_property, $field->position);
         }
     }
     foreach ($this->groups as $group) {
         $group->fixLabel($this->tr_node, $this->admin_object->generator->sf_domain);
         $group->sort();
     }
 }