Example #1
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();
     }
 }