X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Adding Tabs to Admin Pages (https://forum.x-cart.com/showthread.php?t=78238)

The Knotty Celt 05-15-2021 11:51 AM

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?

Ed B. 05-24-2021 09:03 AM

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;
    }


The Knotty Celt 06-06-2021 08:06 AM

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!


All times are GMT -8. The time now is 05:44 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.