Jump to content

Need help with module override !


El Pipo

Recommended Posts

Hi the community !

 

I try to add functionnalities to the authentication process. I thought the best way was to create a module that will override authentication controller...

 

At the beginning, I did it good putting it in in the right override directory of my module. But after, I also need to change the default template for authentication. I don't want to touch the default core theme, neither to create a new theme as my customer asks me to deliver his order as a module saying the designers will override my module templates.

 

So I thought I had to include this new template (based on the default one) in my module and modify the overrride controler to point to this template instead of the default one. This leads me to change the end of the function initContent of my AuthController override class but I'm not very proud of my code being force to set the path manually :

 

 $this->setTemplate(_PS_MODULE_DIR_.'egcustomer'.'/views/templates/front/controlers/authentication.tpl');

 

Of course I also want to attach specific string translation to this template. But, I don't manage it.

 

So at the end, I just wonder if I'm not simply in a bad way?

 

Any opinions would be greattly appreciated.

 

By the way it's said in the documentation that Tools::displayError should be avoided in modules, but what to do instead?... Especially when the methods of the controller I override are full of them ?

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

  • 4 weeks later...

Well, I answer to myself in case of...

 

There is another way to do it that seems more compliant: no need to override function initContent of the controller. But documentation has not been found, so I don't know if it will be kept in next versions.

 

It still doesn't allow override of the template in the theme, but anyway AuthenticationController is not really theme compliant already :( .

 

So, in most circonstances, you should be able to do this in your module, if you want to override a controller template:

public function install()  // That's the one of your module !
{
 if (parent::install() == false || $this->registerHook('DisplayOverrideTemplate') == false)
  return false;
 return true;
}

public function hookDisplayOverrideTemplate($params)
{
 $controller = get_class($params['controller']);
 switch($controller) {
  case 'AuthController':
return $this->local_path.'views/templates/front/authentication.tpl'; // Or whatever you want
  default:
return false;
 }
}

 

Sadly, as far as I understand FrontController Class doesn't handle theme template override for the moment. It doesn't look so hard to implement in SetTemplate function.

  • Thanks 2
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...