Jump to content

How to enable accessing a module config from a tab?


omnitroy

Recommended Posts

When I install a module, usually, I can only config it by clicking the module tab and search for that specific module, and then "configure" it.

 

Question is: is it possible that we can hook that configure part to becoming a tab in the back-end?

 

For example, minic slider module. What if I want to just click a tab in the admin panel to access it?

Link to comment
Share on other sites

The only approach I am aware of is to include an AdminModuleTab class with your module, that implements your configuration.

 

So instead of implementing your configuration from within the module, you simply redirect to the AdminModuleTab, like below.

   public function getContent()
   {
       global $cookie;
       $tab = 'AdminModuleMenu';
       $token = Tools::getAdminToken($tab.(int)(Tab::getIdFromClassName($tab)).(int)($cookie->id_employee));
       Tools::redirectAdmin('index.php?tab=' . $tab . '&token=' . $token);
   }

Link to comment
Share on other sites

The only approach I am aware of is to include an AdminModuleTab class with your module, that implements your configuration.

 

So instead of implementing your configuration from within the module, you simply redirect to the AdminModuleTab, like below.

public function getContent()
{
	global $cookie;
	$tab = 'AdminModuleMenu';
	$token = Tools::getAdminToken($tab.(int)(Tab::getIdFromClassName($tab)).(int)($cookie->id_employee));
	Tools::redirectAdmin('index.php?tab=' . $tab . '&token=' . $token);
}

 

 

I built a tag in admin HOME, called "Slide" and class name "AdminSlide".

 

And I changed the getContent function within slideric module and it redirects to Slide Tag ---- but it is only when I click the Module tag and reach the slideric module and configuring it, it redirects to the slider Tag.

 

In fact, what I really want is that when I click the Slide Tag, it redirects to the configuration of the slideric module.

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

I'm searching how to do similarly to this but a little bit different.

 

We are modifying PrestaShop tabs' access for different roles and I need to make a slider configuration from a tab / sub-tab, e.g. under Tools tab. Redirecting to module is not a solution because modules can't be accessed from that specific role.

 

Is there any solution how to achieve this?

 

Thanks

Link to comment
Share on other sites

  • 3 months later...

In fact, I still do not succeed in making a tab in the back-end that accessing a module. But I am beating it around: I use Quick Access to point to the URL of an module configuring. So.

 

I was trying to do this but somehow I keep getting invalid security tokens... Any ideas?

Cheers

Link to comment
Share on other sites

  • 2 months later...

@bellini13, will this work for v1.5?

The only approach I am aware of is to include an AdminModuleTab class with your module, that implements your configuration.

 

So instead of implementing your configuration from within the module, you simply redirect to the AdminModuleTab, like below.

public function getContent()
{
	global $cookie;
	$tab = 'AdminModuleMenu';
	$token = Tools::getAdminToken($tab.(int)(Tab::getIdFromClassName($tab)).(int)($cookie->id_employee));
	Tools::redirectAdmin('index.php?tab=' . $tab . '&token=' . $token);
}

Link to comment
Share on other sites

  • 4 months later...

The only approach I am aware of is to include an AdminModuleTab class with your module, that implements your configuration.

 

So instead of implementing your configuration from within the module, you simply redirect to the AdminModuleTab, like below.

public function getContent()
{
	global $cookie;
	$tab = 'AdminModuleMenu';
	$token = Tools::getAdminToken($tab.(int)(Tab::getIdFromClassName($tab)).(int)($cookie->id_employee));
	Tools::redirectAdmin('index.php?tab=' . $tab . '&token=' . $token);
}

 

It's not clear why you add employee cookie to the end of token, it should work without that (tested on PS 1.5)

public function initContent() {
$tab = 'AdminModules';
$configure=$module_name='blockcart';
$tab_module='front_office_features';
$token = Tools::getAdminTokenLite($tab);
Tools::redirectAdmin('index.php?tab=' . $tab . '&token=' . $token . '&configure='.$configure.'&tab_module='.$tab_module.'&module_name='.$module_name);
}

Link to comment
Share on other sites

It's not clear why you add employee cookie to the end of token, it should work without that (tested on PS 1.5)

public function initContent() {
$tab = 'AdminModules';
$configure=$module_name='blockcart';
$tab_module='front_office_features';
$token = Tools::getAdminTokenLite($tab);
Tools::redirectAdmin('index.php?tab=' . $tab . '&token=' . $token . '&configure='.$configure.'&tab_module='.$tab_module.'&module_name='.$module_name);
}

 

If you look at the AdminTab class, you will see that is how Prestashop creates the token.

$this->token = Tools::getAdminToken($className.(int)$this->id (int)$this->context->employee->id);

Link to comment
Share on other sites

If you look at the AdminTab class, you will see that is how Prestashop creates the token.

$this->token = Tools::getAdminToken($className.(int)$this->id (int)$this->context->employee->id);

 

getAdminTokenLite() is simplified version of getAdminToken() (does practically the same), source code excerpt from ToolsCore class (Tools.php file):

 

public static function getAdminToken($string)
{
	return !empty($string) ? Tools::encrypt($string) : false;
}

public static function getAdminTokenLite($tab, Context $context = null)
{
	if (!$context)
		$context = Context::getContext();
	return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$context->employee->id);
}

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...