Jump to content

How can I override form.tpl using AdminController::renderForm() ?


Recommended Posts

Hi,

 

Prestashop 1.5.x recommends using AdminController::renderForm() for rendering.

There is a path of the classes cooperation:

AdminController::renderForm() -> HelperForm::generateForm() -> HelperForm::generate() -> Hepler::generate() and Helper::createTemplate()

 

public function renderForm()
{
 if (!$this->default_form_language)
  $this->getLanguages();
 if (Tools::getValue('submitFormAjax'))
  $this->content .= $this->context->smarty->fetch('form_submit_ajax.tpl');
 if ($this->fields_form && is_array($this->fields_form))
 {
  if (!$this->multiple_fieldsets)
$this->fields_form = array(array('form' => $this->fields_form));
  // For add a fields via an override of $fields_form, use $fields_form_override
  if (is_array($this->fields_form_override) && !empty($this->fields_form_override))
$this->fields_form[0]['form']['input'][] = $this->fields_form_override;
  $helper = new HelperForm($this);
  $this->setHelperDisplay($helper);
  $helper->fields_value = $this->getFieldsValue($this->object);
  $helper->tpl_vars = $this->tpl_form_vars;
  !is_null($this->base_tpl_form) ? $helper->base_tpl = $this->base_tpl_form : '';
  if ($this->tabAccess['view'])
  {
if (Tools::getValue('back'))
 $helper->tpl_vars['back'] = Tools::safeOutput(Tools::getValue('back'));
else
 $helper->tpl_vars['back'] = Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token));
  }
  $form = $helper->generateForm($this->fields_form);
  return $form;
 }
}

 

/**
 * Create a template from the override file, else from the base file.
 *
 * @param string $tpl_name filename
 * @return Template
 */
public function createTemplate($tpl_name)
{
 if ($this->override_folder)
 {
  if ($this->context->controller instanceof ModuleAdminController)
$override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name;
  else if ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name;
  } else
  {
if (file_exists($this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name))
 $override_tpl_path = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name;
else if (file_exists($this->context->smarty->getTemplateDir(0).DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name))
 $override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name;
  }
 }
 else if ($this->module) {
  $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name;
	}
 if (isset($override_tpl_path) && file_exists($override_tpl_path))
  return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty);
 else
  return $this->context->smarty->createTemplate($this->base_folder.$tpl_name, $this->context->smarty);
}

 

But how i can set the $helper->mobile value? Is there the right way without any method overrides? And what is the strange file path uses ($override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name;)?

 

Regards

Edited by Alexander Simonchik (see edit history)
Link to comment
Share on other sites

  • 3 months later...
  • 8 months later...

There is a very simple solution. 

Gor to your admin/theme/ directory !

 

Make a new folder, the name you want !

 

Copy and past the entire default theme in your new folder.

 

Then in the backoffice, in your preference, chooses the new themes you just create the folder.

 

Move what you want into this new theme ! You won't loose it in case of upgrade.

Link to comment
Share on other sites

×
×
  • Create New...