Jump to content

how to add an admin tab when override is disabled?


Recommended Posts

i would like to add admin tab, i defined a controller and install the tab with this function: 

public function installTab($class_name, $tabname)  {
    $tab = new Tab();
    // Define the title of your tab that will be displayed in BO
    $tab->name[$this->context->language->id] = $tabname;
    // Name of your admin controller
    $tab->class_name = $class_name;
    // Id of the controller where the tab will be attached
    // If you want to attach it to the root, it will be id 0 (I'll explain it below)
    $tab->id_parent = 0;
    $tab->active = 1;
    // Name of your module, if you're not working in a module, just ignore it, it will be set to null in DB
    $tab->module = $this->name;
    // Other field like the position will be set to the last, if you want to put it to the top you'll have to modify the position fields directly in your DB
    $tab->add();
    return true;
}

and my controller is defined like this: 

class AdminBarCodeGeneratorAdminController extends AdminController
{


 /** @var Smarty */
    public $smarty;
    public function __construct(){
        parent::__construct();
    }

public function initContent()
{
    parent::initContent();
    $scan_form=$this->renderForm();
    $this->smarty->assign('scan_form',$scan_form);
    $this->setTemplate(_PS_MODULE_DIR_.'BarCodeGenerator/views/templates/admin/tabs/scan.tpl');  
}



protected function renderForm()
{
    $this->loadAsset();
    $helper = new HelperForm();
    $helper->show_toolbar = false;
    $helper->table = $this->table;
    $helper->module = $this;
    $helper->default_form_language = $this->context->language->id;
    $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

    $helper->identifier = $this->identifier;
    $helper->submit_action = $action;
    $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
        .'&configure='.$this->name.'&module_name='.$this->name;
    
        
          $helper->currentIndex .= '&id_BarCodeGenerator='.(int)Tools::getValue('id_BarCodeGenerator');
     

    $helper->token = Tools::getAdminTokenLite('AdminModules');
   
    
    $helper->tpl_vars = array(
        'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
        'languages' => $this->context->controller->getLanguages(),
        'id_language' => $this->context->language->id,
        
    );


    return $helper->generateForm(array($this->getConfigForm()));
}

public function getConfigFormValues(){
    return array(
        'prefixe2'=>Tools::getValue('prefixe2'),
        'reference'=>Tools::getValue('reference'),
        'key'=>Tools::getValue('key')
    );
}

protected function getConfigForm(){
    return array(

        'form' => array(
            'legend' => array(
            'title' => $this->l('Scan des codes barres'),
            'icon' => 'icon-qrcode',
            ),
            'input' => array(
     
                array(
                    'col' => 3,
                    'type' => 'text',
                    //'prefix' => '<i class="icon icon-envelope"></i>',
                    'desc' => $this->l('Entrez le prefix du code barre'),
                    'name' => 'prefixe2',
                    'label' => $this->l('Prefixe'),
                    'required'=>true
                ),
                array(
                    'col' => 3,
                    'type' => 'text',
                    //'prefix' => '<i class="icon icon-envelope"></i>',
                    'desc' => $this->l('Entrez la reférence de la commande'),
                    'name' => 'reference',
                    'label' => $this->l('Reférence commande'),
                    'required'=>true
                ),
                array(
                    'col' => 3,
                    'type' => 'text',
                    //'prefix' => '<i class="icon icon-envelope"></i>',
                    'desc' => $this->l('Entrez la clé du code barre'),
                    'name' => 'key',
                    'label' => $this->l('key'),
                    'required'=>true
                ),
             
        ),
            'submit' => array(
                'title' => $this->l('Mettre à jour le statut'),
            ),
           
        ),
        
   
        );
}
}

but the shop i want to deploy it has the particularity the overrides are disabled, so i tried to insert the controller with two methods:

public function hookModuleRoutes($params){
  return [
      'module-BarCodeGenerator-AdminBarCodeGeneratorAdmin'=>[
          'controller'=>'AdminBarCodeGeneratorAdmin'
          ]
      ];
}

in this case, the hook did not even install successfully 

-by adding manually the controller in the config/routes.yml

scanTab: 
path: BarCodeGenerator/demo
methods: [GET]
defaults:
  _controller: 'BarCodeGenerator/controllers/admin/AdminBarCodeGeneratorAdminController::initContent'
  _legacy_controller: 'AdminBarCodeGeneratorAdminController'
  _legacy_link: 'AdminBarCodeGeneratorAdminController'

but none of these methods worked

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...