Ejemplo n.º 1
0
 /**
  * Creates a new Form object
  *
  * @param   string  $name      The name of the form.
  * @param   string  $source    The form source filename without path and .xml extension e.g. "form.default" OR raw XML data
  * @param   string  $viewName  The name of the view you're getting the form for.
  * @param   array   $options   Options to the Form object
  * @param   bool    $replace   Should form fields be replaced if a field already exists with the same group/name?
  * @param   bool    $xpath     An optional xpath to search for the fields.
  *
  * @return  Form|null  The loaded form or null if the form filename doesn't exist
  *
  * @throws  \RuntimeException If the form exists but cannot be loaded
  */
 public function form($name, $source, $viewName, array $options = array(), $replace = true, $xpath = false)
 {
     // Get a new form instance
     $form = new Form($this->container, $name, $options);
     // If $source looks like raw XML data, parse it directly
     if (strpos($source, '<form') !== false) {
         if ($form->load($source, $replace, $xpath) === false) {
             throw new FormLoadData();
         }
         return $form;
     }
     $formFileName = $this->getFormFilename($source, $viewName);
     if (empty($formFileName)) {
         if ($this->scaffolding) {
             $scaffolding = new ScaffoldingBuilder($this->container);
             $xml = $scaffolding->make($source, $viewName);
             if (!is_null($xml)) {
                 return $this->form($name, $xml, $viewName, $options, $replace, $xpath);
             }
         }
         return null;
     }
     if ($form->loadFile($formFileName, $replace, $xpath) === false) {
         throw new FormLoadFile($source);
     }
     return $form;
 }
Ejemplo n.º 2
0
 /**
  * Push the form and strings to the builder
  */
 protected function pushResults()
 {
     $this->builder->setStrings($this->strings);
     $this->builder->setXml($this->xml);
 }