Jump to content

Creating video section in admin to manage and display in fornt-end


Recommended Posts

I am using prestashop version 1.6 in localhost. I need to add our own video section  in admin / back office to manage and display those videos in a separate page in front end. For example, about us and term and conditions pages like that.

 

I have developed my own module upto configuration section of the module. Now i need to add my own form fields like title, embedcode and submit button. I dont know how to add our own form fields with "helper class" of prestashop. Also i have read the documentation but could not able to get. Can you guide me please ? Thanks in advance and sorry for my english. :)

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

I'd forget the helper class. It's very limited in terms of functionality, and overly complex. I generally work my own way by copying outputs somewhere and adding them manually, like:

						<h4>'.$this->l('Add a category').'</h4>
						
						<div class="form-group">
							<label class="control-label col-lg-2">'.$this->l('Parent ID').'</label>
							<div class="col-lg-3">
								<input type="text" name="parentFilter" value="'.(Tools::isSubmit('parentFilter') ? Tools::getValue('parentFilter') : '').'"/>
							</div>
							<div class="col-lg-2">
								<input class="btn btn-default" type="submit" name="submitParentFilter" value="'.$this->l('Filter!').'" >
							</div>
						</div>
  • Like 1
Link to comment
Share on other sites

ok fine nemo.., Below is my code for your reference and kindly let me know where can i add these lines please ?

 

videomodule.php:

 

<?php

            if (!defined('_PS_VERSION_'))
              exit;
            class VideoModule extends Module
            {
                public function __construct()
                {
                    $this->name = 'videomodule';
                    $this->tab = 'video';
                    $this->version = 1.0;
                    $this->author = 'Dinesh Kumar';
                    $this->need_instance = 0;
                    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
                    $this->bootstrap = true;
                
                    parent::__construct();
                
                    $this->displayName = $this->l('Video Module');
                    $this->description = $this->l('It is really an awesome experience');
                    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
              Configuration::updateValue('video', serialize(array(true, true, false)));
                    if (!Configuration::get('videomodule'))      
                          $this->warning = $this->l('No name provided');

                  //    echo Configuration::get('videoid');
                }
            public function getContent()
            {
                $output = null;
             
                if (Tools::isSubmit('submit'.$this->name))
                {
                    $my_module_name = strval(Tools::getValue('videomodule'));
                    if (!$my_module_name
                      || empty($my_module_name)
                      || !Validate::isGenericName($my_module_name))
                        $output .= $this->displayError($this->l('Invalid Configuration value'));
                    else
                    {
                        Configuration::updateValue('videomodule', $my_module_name);
                        $output .= $this->displayConfirmation($this->l('Settings updated'));
                    }
                }
                return $output.$this->displayForm();
            }

            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' => 'videomodule',
                            'size' => 20,
                            'required' => true
                        )
                    ),
                    
                    'submit' => array(
                        'title' => $this->l('Save'),
                        'class' => 'button'
                    )
                );
               

                 
                $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['videomodule'] = Configuration::get('videomodule');
             
            return $helper->generateForm($fields_form);
            }

                public function install()
                {
                  if (Shop::isFeatureActive())
                    Shop::setContext(Shop::CONTEXT_ALL);
                
                  if (!parent::install() ||
                    !$this->registerHook('leftColumn') ||
                    !$this->registerHook('header') ||
                    !Configuration::updateValue('videomodule', 'my friend')

                  )
                    return false;
                
                  return true;
                }
               

                public function uninstall()
                {
                  if (!parent::uninstall() ||
                    !Configuration::deleteByName('videomodule')
                  )
                    return false;
                
                  return true;
                }

              public function hookLeftColumn( $params )
              {
                  global $smarty;
                  return $this->display(__FILE__,'videomodule.tpl');
              }
             
            public function hookRightColumn($params)
              {
                  return $this->hookLeftColumn($params);
              }


            }

Link to comment
Share on other sites

DisplayForm. You must get rid of all that and use manual code instead. Make sure you open a div classed "panel"  inside a form with class "defaultForm form-horizontal"

 

 

  <form action="'.$_SERVER['REQUEST_URI'].'" method="post" class="defaultForm form-horizontal">
 
   <div class="panel">
...
</div>
</form>
Link to comment
Share on other sites

×
×
  • Create New...