Creates an automatic XML form definition to render a view based on the database fields you've got in the model. This is not designed for production; it's designed to give you a way to quickly add some test data to your component and get started really fast with FOF development.
Ejemplo n.º 1
0
 /**
  * Create the xml file for a give view type
  * @param  string $view      The view name
  * @param  string $viewType  The type of the view (default, form, item)
  * @param  boolean $backend   If it's for the backend
  *
  * @return string            The xml generated
  *
  * @throws \Exception Can throw exceptions. @see LayoutBuilder
  */
 protected function createViewFile($view, $viewType, $backend)
 {
     // Let's force the use of the Magic Factory
     $container = Container::getInstance($this->component, array('factoryClass' => 'FOF30\\Factory\\MagicFactory'));
     $container->factory->setSaveScaffolding(true);
     // plural / singular
     if ($viewType != 'default') {
         $view = $container->inflector->singularize($view);
     }
     // Small trick: being in the CLI, the builder always tries to build in the frontend
     // Let's switch paths :)
     $originalFrontendPath = $container->frontEndPath;
     $originalBackendPath = $container->backEndPath;
     $container->frontEndPath = $backend ? $container->backEndPath : $container->frontEndPath;
     $scaffolding = new LayoutBuilder($container);
     $return = $scaffolding->make('form.' . $viewType, $view);
     // And switch them back!
     $container->frontEndPath = $originalFrontendPath;
     $container->backEndPath = $originalBackendPath;
     return $return;
 }
Ejemplo n.º 2
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 LayoutBuilder($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.º 3
0
 /**
  * Push the form and strings to the builder
  */
 protected function pushResults()
 {
     $this->builder->setStrings($this->strings);
     $this->builder->setXml($this->xml);
 }