Magento add external URL to menu admin

I was just trying to add an external link on my admin menu panel and figured out that there is no direct option to add, we need to override some functionality to achieve this. So here is the solution I found out for the same. Unfortunately, we need to have a small module for this functionality:-

Firstly we need to overwrite the _buildMenuArray() function of Mage_Adminhtml_Block_Page_Menu class to add a condition for external url. So let’s start our modification:-

Create your config file to override the page menu class, as shown in below code:

<config>
    <modules>
        <W3solver_Menulink>
            <version>1.0.0</version>
        </W3solver_Menulink>
    </modules>
	
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <page_menu>W3solver_Menulink_Block_Adminhtml_Page_Menu</page_menu>
                </rewrite>
            </adminhtml>
        </blocks>
        <helpers>
            <menulink>
                <class>W3solver_Menulink_Helper</class> 
            </menulink>
        </helpers>
    </global>
</config>

Add a block file to override page menu, review line 40 for the modification:-

class W3solver_Menulink_Block_Adminhtml_Page_Menu extends Mage_Adminhtml_Block_Page_Menu {
    
    /**
     * Recursive Build Menu array
     *
     * @param Varien_Simplexml_Element $parent
     * @param string $path
     * @param int $level
     * @return array
     */
    protected function _buildMenuArray(Varien_Simplexml_Element $parent=null, $path='', $level=0)
    {
        if (is_null($parent)) {
            $parent = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu');
        }

        $parentArr = array();
        $sortOrder = 0;
        foreach ($parent->children() as $childName => $child) {
            if (1 == $child->disabled) {
                continue;
            }

            $aclResource = 'admin/' . ($child->resource ? (string)$child->resource : $path . $childName);
            if (!$this->_checkAcl($aclResource) || !$this->_isEnabledModuleOutput($child)) {
                continue;
            }

            if ($child->depends && !$this->_checkDepends($child->depends)) {
                continue;
            }

            $menuArr = array();

            $menuArr['label'] = $this->_getHelperValue($child);

            $menuArr['sort_order'] = $child->sort_order ? (int)$child->sort_order : $sortOrder;

            /* condition added to manage external url*/
            if ($child->external_url) {
                $menuArr['url'] = (string)$child->external_url;
            } else if ($child->action) {
                $menuArr['url'] = $this->_url->getUrl((string)$child->action, array('_cache_secret_key' => true));
            } else {
                $menuArr['url'] = '#';
                $menuArr['click'] = 'return false';
            }

            $menuArr['active'] = ($this->getActive()==$path.$childName)
                || (strpos($this->getActive(), $path.$childName.'/')===0);

            $menuArr['level'] = $level;

            if ($child->children) {
                $menuArr['children'] = $this->_buildMenuArray($child->children, $path.$childName.'/', $level+1);
            }
            $parentArr[$childName] = $menuArr;

            $sortOrder++;
        }

        uasort($parentArr, array($this, '_sortMenu'));

        while (list($key, $value) = each($parentArr)) {
            $last = $key;
        }
        if (isset($last)) {
            $parentArr[$last]['last'] = true;
        }

        return $parentArr;
    }

 

Here is code of my menu:-

<config>
    <menu>
        <menulink translate="title" module="menulink">
            <title>Menu Link</title>
            <sort_order>400</sort_order>
            <children>
                <menulink translate="title" module="menulink">
                    <title>Menu Link</title>
                    <sort_order>1</sort_order>
                    <external_url>http:www.google.com</external_url>
                </menulink>
            </children>
        </menulink>
    </menu>
</config>

Just put down your comment if you face any issue.

10 Comments

  1. Hey there, You’ve performed an excellent job. I will definitely digg it and in my opinion recommend to my friends. I’m confident they will be benefited from this web site.

    Reply
  2. I was just searching for this info for some time. After 6 hours of continuous Googleing, finally I got it in your web site. I wonder what’s the lack of Google strategy that do not rank this kind of informative websites in top of the list. Generally the top web sites are full of garbage.

    Reply
  3. Pretty Very great nice post. I simply just stumbled upon your blog and wished to mention to say that I’ve really enjoyed browsing around your blog posts.

    Reply
  4. Hey there! I know this is somewhat off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having difficulty finding one? Thanks a lot!

    Reply
  5. Excellent post. I was checking continuously this weblog and I’m impressed! Very helpful info specially the remaining section 🙂 I handle such information much. I was seeking this particular info for a long time. Thank you and good luck.

    Reply
  6. Having read this I thought it was rather enlightening.
    I appreciate you finding the time and effort to put this content together.
    I once again find myself personally spending a significant amount of time both reading
    and leaving comments. But so what, it was still worthwhile!

    Reply

Leave a Comment.