public function generateForm($params, $content, \Smarty_Internal_Template $template, &$repeat) { if ($repeat) { $name = $this->getParam($params, 'name'); $formType = $this->getParam($params, 'type', 'form'); if (null == $name) { $name = "thelia.empty"; } if (!isset($this->formDefinition[$name])) { throw new ElementNotFoundException(sprintf("%s form does not exists", $name)); } $formClass = $this->formDefinition[$name]; // Check if parser context contains our form $instance = $this->parserContext->getForm($name, $formClass, $formType); if (null === $instance) { // If not, create a new instance $instance = $this->formFactory->createForm($name); } // Set the current form $this->parserContext->pushCurrentForm($instance); $instance->createView(); $template->assign("form", $instance); $template->assign("form_name", $instance->getName()); $template->assign("form_error", $instance->hasError() ? true : false); $template->assign("form_error_message", $instance->getErrorMessage()); } else { $this->parserContext->popCurrentForm(); return $content; } }
public function generateForm($params, $content, \Smarty_Internal_Template $template, &$repeat) { if ($repeat) { $name = $this->getParam($params, 'name'); if (null == $name) { throw new \InvalidArgumentException("Missing 'name' parameter in form arguments"); } if (!isset($this->formDefinition[$name])) { throw new ElementNotFoundException(sprintf("%s form does not exists", $name)); } $formClass = $this->formDefinition[$name]; // Check if parser context contains our form $form = $this->parserContext->getForm($formClass); if (null != $form) { // Re-use the form $instance = $form; } else { // Create a new one $class = new \ReflectionClass($formClass); $instance = $class->newInstance($this->request, "form"); } $instance->createView(); $template->assign("form", $instance); $template->assign("form_error", $instance->hasError() ? true : false); $template->assign("form_error_message", $instance->getErrorMessage()); } else { return $content; } }