示例#1
0
文件: Form.php 项目: alex63530/thelia
 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;
     }
 }
示例#2
0
文件: Form.php 项目: jantotof/thelia
 /**
  * @param $params
  * @return BaseForm
  * @throws \InvalidArgumentException
  */
 protected function getInstanceFromParams($params)
 {
     if (null === ($instance = $this->getParam($params, 'form'))) {
         $instance = $this->parserContext->getCurrentForm();
     }
     if (null == $instance) {
         throw new \InvalidArgumentException("Missing 'form' parameter in form arguments, and no current form was found.");
     }
     if (!$instance instanceof BaseForm) {
         throw new \InvalidArgumentException(sprintf("form parameter in form_field block must be an instance of " . "\\Thelia\\Form\\BaseForm, instance of %s found", get_class($instance)));
     }
     return $instance;
 }