Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Adding Tabs to Admin Pages

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 05-15-2021, 11:51 AM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default Adding Tabs to Admin Pages

So, I followed this guide (https://devs.x-cart.com/design_changes/adding_tabs.html) in order to learn how to add a tab to an Admin Page. It worked in adding the custom tab to the Products page, however; when I tried to implement the same procedure to add a tab to the Front Page settings page, it simply added the body of my tab's template between the page title and the row of tabs.

Code:
<?php // vim: set ts=4 sw=4 sts=4 et: namespace XLite\Module\LBS\MultiLingualBanner\Controller\Admin; /** * Front Page */ abstract class FrontPage extends \XLite\Controller\Admin\FrontPage implements \XLite\Base\IDecorator { public function getPages() { $list = parent::getPages(); $list['custom_tab'] = 'My Custom Tab'; return $list; } protected function getPageTemplates() { $list = parent::getPageTemplates(); $list['custom_tab'] = 'modules/LBS/MultiLingualBanner/tab/custom_tab.twig'; return $list; } }


Are the tabs on this page handled differently than those on the Products page? How can I properly place my template as a tab on the Front Page settings page?
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote
  #2  
Old 05-24-2021, 09:03 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default Re: Adding Tabs to Admin Pages

As a matter of fact the tabs are handled differently. You can look at the code of the controller class for front page, and you will see that there is no method called getPages()


Instead the class View/Tabs/FrontPage.php has a method called defineTabs()
Code:
/** * @return array */ protected function defineTabs() { $tabs = []; if (Auth::getInstance()->isPermissionAllowed(Permission::ROOT_ACCESS) || Auth::getInstance()->isPermissionAllowed('manage front page')) { $tabs['front_page'] = [ 'weight' => 100, 'title' => static::t('Front page'), 'template' => 'front_page/body.twig', ]; } if (Auth::getInstance()->isPermissionAllowed('manage banners')) { $tabs['banner_rotation'] = [ 'weight' => 200, 'title' => static::t('Banner rotation'), 'template' => 'banner_rotation/body.twig', ]; } return $tabs; }
so you have to decorate this method. In case you have difficulty in finding out the right code, you can take a look at the following code in the class XLite/Module/CDev/FeaturedProducts/View/Tabs/FrontPage.php


Code:
/** * @return array */ protected function defineTabs() { $list = parent::defineTabs(); $list['featured_products'] = [ 'weight' => 300, 'title' => static::t('Featured products'), 'template' => 'modules/CDev/FeaturedProducts/featured_products.twig' , ]; return $list; }
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #3  
Old 06-06-2021, 08:06 AM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default Re: Adding Tabs to Admin Pages

Thank you, Ed.


I have managed to add the tab, and even have my module's configuration settings show up here. Somehow, though, the form table for adding records to the module's models is not showing up. That, however is the subject matter for another thread. Thanks again for pointing me in the right direction.


Cheers!
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:54 PM.

   

 
X-Cart forums © 2001-2020