...
Your module can get a "Configure" link in the back - office module list, and therefore let the user change some settings. This "Configure" link appears with addition of the getContent()
method to your main class. This is a standard PrestaShop method: its sole existence sends a message to the back - office, saying "there's a configuration page in this module, display the configuration link".
...
Code Block |
---|
public function displayForm() { // Get default language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Configuration value'), 'name' => 'MYMODULE_NAME', 'size' => 20, 'required' => true ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'buttonbtn btn-default pull-right' ) ); $helper = new HelperForm(); // Module, token and currentIndex $helper->module = $this; $helper->name_controller = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; // Language $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; // Title and toolbar $helper->title = $this->displayName; $helper->show_toolbar = true; // false -> remove toolbar $helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen. $helper->submit_action = 'submit'.$this->name; $helper->toolbar_btn = array( 'save' => array( 'desc' => $this->l('Save'), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. '&token='.Tools::getAdminTokenLite('AdminModules'), ), 'back' => array( 'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list') ) ); // Load current value $helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME'); return $helper->generateForm($fields_form); } |
...
HelperForm
is one of the helper methods that were added with PrestaShop 1.5, along with HelperOptions
, HelperList
, HelperView
and HelperHelpAccess
. They enable you to generate standard HTML elements for the back - office as well as for module configuration pages.
You can get more information about Helper classes in the "Helpers" chapter of this developer guide, with a page dedicated to HelperForm
.
...
Here is the rendition of the form as it is presently written – which you can see by yourself by clicking on the "Configure" link for the module in the back - office:
Change the value to whichever you like, click on the "Save" button, then go reload the homepage: your module is indeed updated with the new string!