protected function buildForm($change_mode = false) { if (!$this->container) { throw new \LogicException(Translator::getInstance()->trans("The container should not be null in this form. Please use the FormFactory to get an instance.")); } /** @var TaxEngine $taxEngine */ $taxEngine = $this->container->get('thelia.taxEngine'); $types = $taxEngine->getTaxTypeList(); $typeList = array(); $requirementList = array(); foreach ($types as $classname) { $instance = new $classname(); $typeList[Tax::escapeTypeName($classname)] = $instance->getTitle(); $requirementList[$classname] = $instance->getRequirementsDefinition(); } $this->formBuilder->add("locale", "hidden", ["constraints" => [new NotBlank()]])->add("type", "choice", ["choices" => $typeList, "required" => true, "constraints" => [new Constraints\NotBlank()], "label" => Translator::getInstance()->trans("Type"), "label_attr" => ["for" => "type_field"]]); foreach ($requirementList as $name => $requirements) { /** @var TaxTypeRequirementDefinition $requirement */ foreach ($requirements as $requirement) { if (!isset(self::$typeList[$requirement->getName()])) { self::$typeList[$requirement->getName()] = $requirement->getType(); } $this->formBuilder->add(Tax::escapeTypeName($name) . ':' . $requirement->getName(), new TheliaType(), ["constraints" => [new Constraints\Callback(["methods" => [[$this, "checkRequirementField"]]])], "attr" => ["tag" => "requirements", "tax_type" => Tax::escapeTypeName($name)], "label_attr" => ["type" => $requirement->getName()], "label" => Translator::getInstance()->trans($requirement->getTitle()), "type" => $requirement->getType()->getFormType(), "options" => $requirement->getType()->getFormOptions()]); } } $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale')); }
protected function buildForm($change_mode = false) { if ($this->taxEngine == null) { throw new \LogicException(Translator::getInstance()->trans("The TaxEngine should be passed to this form before using it.")); } $types = $this->taxEngine->getTaxTypeList(); $typeList = array(); $requirementList = array(); foreach ($types as $classname) { $instance = new $classname(); $typeList[Tax::escapeTypeName($classname)] = $instance->getTitle(); $requirementList[$classname] = $instance->getRequirementsDefinition(); } $this->formBuilder->add("locale", "text", array("constraints" => array(new NotBlank())))->add("type", "choice", array("choices" => $typeList, "required" => true, "constraints" => array(new Constraints\NotBlank()), "label" => Translator::getInstance()->trans("Type"), "label_attr" => array("for" => "type_field"))); foreach ($requirementList as $name => $requirements) { foreach ($requirements as $requirement) { $this->formBuilder->add(Tax::escapeTypeName($name) . ':' . $requirement->getName(), new TheliaType(), array("constraints" => array(new Constraints\Callback(array("methods" => array(array($requirement->getType(), "verifyForm"))))), "attr" => array("tag" => "requirements", "tax_type" => Tax::escapeTypeName($name)), "label" => Translator::getInstance()->trans($requirement->getName()), "type" => $requirement->getType()->getFormType(), "options" => $requirement->getType()->getFormOptions())); } } $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale')); }
public function parseResults(LoopResult $loopResult) { /** @var TaxModel $tax */ foreach ($loopResult->getResultDataCollection() as $tax) { $loopResultRow = new LoopResultRow($tax); $loopResultRow->set("ID", $tax->getId())->set("TYPE", $tax->getType())->set("ESCAPED_TYPE", TaxModel::escapeTypeName($tax->getType()))->set("REQUIREMENTS", $tax->getRequirements())->set("IS_TRANSLATED", $tax->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $tax->getVirtualColumn('i18n_TITLE'))->set("DESCRIPTION", $tax->getVirtualColumn('i18n_DESCRIPTION')); $this->addOutputFields($loopResultRow, $tax); $loopResult->addRow($loopResultRow); } return $loopResult; }
protected function hydrateObjectForm($object) { $data = array('id' => $object->getId(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'description' => $object->getDescription(), 'type' => Tax::escapeTypeName($object->getType())); // Setup the object form return $this->createForm(AdminForm::TAX_MODIFICATION, "form", $data); }
protected function hydrateObjectForm($object) { $data = array('id' => $object->getId(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'description' => $object->getDescription(), 'type' => Tax::escapeTypeName($object->getType())); // Setup the object form return new TaxModificationForm($this->getRequest(), "form", $data, ["tax_engine" => $this->container->get('thelia.taxEngine')]); }