Magento Admin – Add System Configuration to Existing Tab

adminadminhtmlconfiguration

I have been following another excellent article by Mr Storm: http://alanstorm.com/custom_magento_system_configuration

However, I've hit a snag. In the admin system config, I have an existing tab that is part of a local module I created.

The tab is created with the following code (app/code/local/Jongosi/Adminhtml/etc/system.xml):

<config>
    <tabs>
        <jongosi module="adminhtml">
            <label>Jongosi</label>
            <sort_order>999</sort_order>
        </jongosi>
    </tabs>
</config>

In subsequent modules that I create locally, I would like to add items to the existing (jongosi) tab.

I'm using the following code (app/code/local/Jongosi/Module/etc/system.xml):

<config>
    <sections>
        <jongosi_module_options translate="label" module="jongosi_module">
            <label>Jongosi Module Options</label>
            <tab>jongosi</tab>
            <frontend_type>text</frontend_type>
            <sort_order>1000</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <module translate="label">
                    <label>Module Options</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>                
                    <fields>
                        <brands translate="label">
                            <label>Brands Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Enable or disable brands.</comment>
                        </brands>
                    </fields>
                </module>
            </groups>
        </jongosi_module_options>
    </sections>
</config>

The tab shows up fine with the items listed one below another, but clicking the links ends in a 404. I have cleared the cache many times (rm -rf var/cache/*) , re-indexed and logged out and in again.

My ACL code looks as follows (app/code/local/Jongosi/Module/etc/adminhtml.xml):

<config>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <jongosi_module_options>
                                            <title>Jongosi Module</title>
                                        </jongosi_module_options>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

How can I get this to work? Thanks!

Best Answer

Assuming you mean the 404 page where there's admin chrome and 404 text in the content area, it sounds like your ACL is setup incorrectly or your current user account lacks the proper ACL credentials to view your new System Configuration section.

First, if your user has the all ACL permissions (i.e. is a system root user and/or the default user created during setup), you'll need to clear your admin session before being able to see the page. Magento caches the individual permissions an admin user has in the session, not the cache. This happens when you login — so your new ACL rule hasn't been added to the list of rules allowed by your user.

Second, it's always best to go right to the source of an error. Take a look at the following section of code.

#File: app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php
protected function _isSectionAllowed($section)
{
    try {
        $session = Mage::getSingleton('admin/session');
        $resourceLookup = "admin/system/config/{$section}";
        if ($session->getData('acl') instanceof Mage_Admin_Model_Acl) {
            $resourceId = $session->getData('acl')->get($resourceLookup)->getResourceId();
            if (!$session->isAllowed($resourceId)) {
                throw new Exception('');
            }
            return true;
        }
    }
    catch (Zend_Acl_Exception $e) {
        $this->norouteAction();
        $this->setFlag('', self::FLAG_NO_DISPATCH, true);
        return false;
    }
    catch (Exception $e) {
        $this->deniedAction();
        $this->setFlag('', self::FLAG_NO_DISPATCH, true);
        return false;
    }
}

This is what triggers a 404 page if you're missing an ACL role. A

var_dump($e->getMessage());
var_dump($resourceLookup);

in each of the catch blocks will tell you why Magento thinks your user doesn't have the right access permissions.