Beispiel #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("}");
 }
 public function writeCache(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $lazy_writer, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer)
 {
     $default_value = $this->getDefaultValue();
     if ($this->_lazy) {
         $lazy_writer->writeln('$this->' . $this->getName() . ' = ' . $this->_class->propertyEncode($default_value) . ' ; ');
         $default_value = null;
     }
     $writer->write("\n");
     if ($this->getDocblock()) {
         $writer->writeln($this->getDocblock());
     }
     $writer->write($this->getVisibility())->write(' $')->write($this->getName())->write(' = ')->write($this->_class->propertyEncode($default_value))->writeln(" ;");
     if ($this->_get) {
         $this->genGetter();
     }
 }
 protected function compileMenu(\Symforce\AdminBundle\Entity\Menu $menu, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer, $deep = 0)
 {
     $li_tag = $menu->menu_group->child_wapper;
     $text_tag = $menu->menu_group->child_tag;
     $class = sprintf('sf_menu_item sf_menu_deep%d ', $deep) . $menu->menu_group->child_class;
     if ('a' === $text_tag) {
         $text_tag = null;
     }
     $icon = $menu->getIconClassName();
     $page = null;
     $text = null;
     $url = '#';
     if ('static' === $menu->type) {
         $url = $menu->static_url;
     } else {
         if ('route' === $menu->type) {
             $route_args = json_decode($menu->route_args);
             if (!is_array($route_args)) {
                 $route_args = array();
             }
             $url = '{{ ' . sprintf('path("%s",%s)', $menu->route_name, json_encode($route_args)) . ' }}';
         } else {
             if ('page' === $menu->type) {
                 $url = '{{ ' . sprintf('menu_service.getPageUrl(%d)', $menu->page->getId()) . ' }}';
                 $text = '{{ ' . sprintf('menu_service.getPageText(%d)', $menu->page->getId()) . ' }}';
             } else {
                 if ('page_route' === $menu->type) {
                     $arg_name = $menu->page_route_arg_name;
                     if (!$arg_name) {
                         $arg_name = 'slug';
                     }
                     $url = '{{ ' . sprintf('path("%s",{"%s": menu_service.getPageSlug(%d) })', $menu->route_name, $arg_name, $menu->page->getId()) . ' }}';
                     if (!$menu->page_menu_title) {
                         $text = '{{ ' . sprintf('menu_service.getPageText(%d)', $menu->page->getId()) . ' }}';
                     }
                 }
             }
         }
     }
     if (!$text) {
         $text = '{{ ' . sprintf('menu_service.getMenuItemText(%d)', $menu->getId()) . ' }}';
     }
     if ($menu->menu_group->child_active_class) {
         if ($menu->menu_group->child_active_var) {
             throw new \Exception('not implement yet');
         } else {
             $class .= '{{ ' . sprintf('menu_service.getMenuItemActiveClass(%d, page)', $menu->getId()) . ' }}';
         }
     }
     if ($li_tag) {
         $writer->write(sprintf('<%s class="%s">', $li_tag, $class));
         $writer->write(sprintf('<a href="%s">', $url));
     } else {
         $writer->write(sprintf('<a href="%s" class="%s">', $url, $class));
     }
     if ($text_tag) {
         $writer->write(sprintf('<%s>', $text_tag));
     }
     if ($icon) {
         $writer->write(sprintf('<i class="fa fa-%s"></i>', $icon));
     }
     $writer->write($text);
     if ($text_tag) {
         $writer->write(sprintf('</%s>', $text_tag));
     }
     if ($li_tag) {
         $writer->write(sprintf('</a>'));
         $this->compileMenuChildren($menu, $writer, $deep);
         $writer->writeln(sprintf('</%s>', $li_tag));
     } else {
         $this->compileMenuChildren($menu, $writer, $deep);
         $writer->writeln(sprintf('</a>'));
     }
 }