Example #1
0
 /**
  * Loads the XML form and pass the fields to the response.
  * Children may need to override this method.
  *
  * @return void
  */
 protected function setForm()
 {
     $component = JComponentHelper::getComponent('com_k2');
     $extension = JTable::getInstance('extension');
     $extension->load($component->id);
     JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_k2');
     $form = JForm::getInstance('com_k2.settings', 'config', array('control' => 'jform'), false, '/config');
     $values = new JRegistry($extension->params);
     $form->bind($values);
     $_form = new stdClass();
     foreach ($form->getFieldsets() as $fieldset) {
         $array = array();
         foreach ($form->getFieldset($fieldset->name) as $field) {
             $tmp = new stdClass();
             $tmp->label = $field->label;
             $tmp->input = $field->input;
             $tmp->type = $field->type;
             $array[$field->name] = $tmp;
         }
         $name = $fieldset->name;
         $_form->{$name} = $array;
     }
     K2Response::setForm($_form);
 }
Example #2
0
 /**
  * Loads the XML form and pass the fields to the response.
  * Usually there would be no need to override this method.
  *
  * @return void
  */
 protected function setForm()
 {
     // Get the row
     $row = K2Response::getRow();
     // Initialize form object
     $_form = new stdClass();
     // Get the dispatcher.
     $dispatcher = JDispatcher::getInstance();
     // Check if form file exists
     jimport('joomla.filesystem.file');
     if (JFile::exists(JPATH_ADMINISTRATOR . '/components/com_k2/models/' . $this->getName() . '.xml')) {
         // Import JForm
         jimport('joomla.form.form');
         // Determine form name and path
         $formName = 'K2' . ucfirst($this->getName()) . 'Form';
         $formPath = JPATH_ADMINISTRATOR . '/components/com_k2/models/' . $this->getName() . '.xml';
         // Convert JRegistry instances to plain object so JForm can bind them
         if (property_exists($row, 'metadata')) {
             $row->metadata = $row->metadata->toObject();
         }
         if (property_exists($row, 'params')) {
             $row->params = $row->params->toObject();
         }
         if (property_exists($row, 'plugins')) {
             $row->plugins = $row->plugins->toObject();
         }
         // Get the form instance
         $form = JForm::getInstance($formName, $formPath);
         // Bind values
         $form->bind($row);
         // Import plugins to extend the form
         JPluginHelper::importPlugin('content');
         // Trigger the form preparation event
         $results = $dispatcher->trigger('onContentPrepareForm', array($form, $row));
         // Pass the JForm to the model before attaching the fields
         $this->prepareJForm($form, $row);
         // Attach the JForm fields to the form
         foreach ($form->getFieldsets() as $fieldset) {
             $array = array();
             foreach ($form->getFieldset($fieldset->name) as $field) {
                 $tmp = new stdClass();
                 $tmp->label = $field->label;
                 $tmp->input = $field->input;
                 $tmp->type = $field->type;
                 $array[$field->name] = $tmp;
             }
             $name = $fieldset->name;
             $_form->{$name} = $array;
         }
     }
     // Extend the form with K2 plugins
     $_form->k2Plugins = array();
     JPluginHelper::importPlugin('k2');
     $dispatcher->trigger('onK2RenderAdminForm', array(&$_form, $row, $this->getName()));
     $this->setFormFields($_form, $row);
     K2Response::setForm($_form);
 }