/** * @return \Symforce\AdminBundle\Compiler\Generator\PhpClass */ public function compile() { $class = $this->getCompileClass(); $class->addProperty('name', $this->name)->addProperty('sf_admin_name', $this->admin_object->name)->addProperty('admin_class', $this->admin_object->class_name)->addProperty('action_name', $this->admin_object->name . '.' . $this->name)->addProperty('icon', $this->icon)->addProperty('tr_domain', $this->admin_object->tr_domain)->addProperty('sf_domain', $this->admin_object->sf_domain); if ($this->template || $this->final_template) { $class->addProperty('template', $this->final_template ?: $this->template); } $class->addProperty('label', $this->label->getPath())->addProperty('label_domain', $this->label->getDomain())->addProperty('action_label', $this->action_label->getPath())->addProperty('action_label_domain', $this->action_label->getDomain())->addProperty('title_label', $this->title_label->getPath())->addProperty('title_label_domain', $this->title_label->getDomain())->addProperty('form_label', $this->form_label->getPath())->addProperty('form_label_domain', $this->form_label->getDomain()); $class->addProperty('is_workflow_action', $this->isWorkflowAuth(), 'bool', null, 'public'); if ($this->isCreateForm()) { $this->compileForm(); } return $class; }
/** * @inherit */ public function getFormOptions() { $options = array('sf_form_type' => $this->compile_form_type, 'sf_form_meta' => $this->compile_meta_type, 'constraints' => array(), 'attr' => array()); if (!$this->label || !$this->label instanceof \Symforce\AdminBundle\Compiler\Generator\TransGeneratorValue) { throw new \Exception(sprintf("label should be \\Symforce\\AdminBundle\\Compiler\\Generator\\TransGeneratorValue, but get `%s` for `%s->%s`", is_object($this->label) ? get_class($this->label) : gettype($this->label), $this->admin_object->class_name, $this->class_property)); } $options['label'] = $this->label->getPhpCode(); if (null !== $this->mapped) { $options['mapped'] = $this->mapped; } if (null !== $this->error_bubbling) { $options['error_bubbling'] = $this->error_bubbling; } if (null !== $this->required) { $options['required'] = $this->required; } else { $options['required'] = !$this->isNullable(); } if (null !== $this->read_only) { $options['read_only'] = $this->read_only; } else { if ($this->auth_node) { $options['read_only'] = $this->compilePhpCode('$this->isPropertyReadonly("' . $this->class_property . '", $action, $object)'); } } if (null !== $this->not_blank) { $options['not_blank'] = $this->not_blank; } if (null !== $this->label_render) { $options['label_render'] = $this->label_render; } if (null !== $this->invalid) { } if (null !== $this->help) { } if (null !== $this->widget) { } if (null !== $this->attr) { } if (null !== $this->wrap) { } if (null !== $this->show_on) { /** * @todo add php code handle */ $options['sf_form_dynamic'] = $this->show_on; } return $options; }
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("}"); }