J1.5

Adding access keys

From Joomla! Documentation

The "J1.5" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Stop hand nuvola.svg.png
Warning!

This is a core hack. Files you change as described on this page will be overwritten during updates of Joomla!. For more information, see Core hack.

Here's a quick way to add access keys to Joomla! 1.5.

Firstly edit the component.xml parameter definiton file in \administrator\components\com_menus\models\metadata and add to it an accesskey parameter:

<param name="accesskey" type="text" size="1" default="" label="Accessibility Access Key"
description="Accessibility Access Key for the page which this Menu item points to" />

Your file should now look something like:

    <?xml version="1.0" encoding="utf-8"?>
    <metadata>
       <state>
          <name>Component</name>
          <description>Component Parameters</description>
          <params>
             <param name="page_title" type="text" size="30" default="" label="Page Title"
               description="PARAMPAGETITLE" />
             <param name="show_page_title" type="radio" default="1" label="Show Page Title"
               description="SHOW/HIDE THE PAGES TITLE">
                <option value="0">No</option>
                <option value="1">Yes</option>
             </param>
             <param name="pageclass_sfx" type="text" size="20" default="" label="Page Class Suffix"
               description="PARAMPAGECLASSSFX" />
             <param name="@spacer" type="spacer" default="" label="" description="" />
             <param name="menu_image" type="imagelist" directory="/images/stories" hide_default="1"
               default="" label="Menu Image" description="PARAMMENUIMAGE" />
             <param name="@spacer" type="spacer" default="" label="" description="" />
             <param name="secure" type="radio" default="0" label="SSL Enabled" description="PARAMSECURE">
                <option value="-1">Off</option>
                <option value="0">Ignore</option>
                <option value="1">On</option>
             </param>
             <param name="@spacer" type="spacer" default="" label="" description="" />
             <param name="accesskey" type="text" size="1" default="" label="Accessibility Access Key"
description="Accessibility Access Key for the page which this Menu item points to" />
          </params>
          <advanced />
       </state>
    </metadata>

Now edit the frontend file \modules\mod_mainmenu\helper.php:

    // ACCESS KEY HACK - Part 1
    $accessKey = $iParams->get('accesskey');
    $tmp->accessKey = $accessKey;

and

    // ACCESS KEY HACK - Part 2
    if ($tmp->accessKey)
    $data = '<a href="'.$tmp->url.'" accesskey="'.$tmp->accessKey.'">'.$image.$tmp->name.'</a>';
    else
    $data = '<a href="'.$tmp->url.'" >'.$image.$tmp->name.'</a>';

into the _getItemData($item) function so that it looks like this

    function _getItemData($item)
       {
          $data = null;

          // Menu Link is a special type that is a link to another item
          if ($item->type == 'menulink')
          {
             $menu = &JSite::getMenu();
             if ($tmp = clone($menu->getItem($item->query['Itemid']))) {
                $tmp->name    = '<span><![CDATA['.$item->name.']]></span>';
                $tmp->mid    = $item->id;
                $tmp->parent = $item->parent;
             } else {
                return false;
             }
          } else {
             $tmp = clone($item);
             $tmp->name = '<span><![CDATA['.$item->name.']]></span>';
          }

          $iParams = new JParameter($tmp->params);
          if ($iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
             $image = '<img src="'.JURI::base(true).'/images/stories/'.$iParams->get('menu_image').'" alt="" />';
          } else {
             $image = null;
          }


          // ACCESS KEY HACK - Part 1
          $accessKey = $iParams->get('accesskey');
          $tmp->accessKey = $accessKey;

          switch ($tmp->type)
          {
             case 'separator' :
                return '<span class="separator">'.$image.$tmp->name.'</span>';
                break;

             case 'url' :
                if ((strpos($tmp->link, 'index.php?') !== false) && (strpos($tmp->link, 'Itemid=') === false)) {
                   $tmp->url = $tmp->link.'&amp;Itemid='.$tmp->id;
                } else {
                   $tmp->url = $tmp->link;
                }
                break;

             default :
                $router = JSite::getRouter();
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ?
                  'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
                break;
          }

          // Print a link if it exists
          if ($tmp->url != null)
          {
             // Handle SSL links
             $iSecure = $iParams->def('secure', 0);
             if ($tmp->home == 1) {
                $tmp->url = JURI::base();
             } elseif (strcasecmp(substr($tmp->url, 0, 4), 'http') && (strpos($tmp->link, 'index.php?') !== false)) {
                $tmp->url = JRoute::_($tmp->url, true, $iSecure);
             } else {
                $tmp->url = str_replace('&', '&amp;', $tmp->url);
             }

             switch ($tmp->browserNav)
             {
                default:
                case 0:
                   // _top
                   // ACCESS KEY HACK - Part 2          ###############################
                   if ($tmp->accessKey)
                      $data = '<a href="'.$tmp->url.'" accesskey="'.$tmp->accessKey.'">'.$image.$tmp->name.'</a>';
                   else
                      $data = '<a href="'.$tmp->url.'" >'.$image.$tmp->name.'</a>';
                   break;
                case 1:
                   // _blank
                   $data = '<a href="'.$tmp->url.'" target="_blank">'.$image.$tmp->name.'</a>';
                   break;
                case 2:
                   // window.open
                   $attribs = 'toolbar=no,location=no,status=no,menubar=no,
                     scrollbars=yes,resizable=yes,'.$this->_params->get('window_open');

                   // hrm...this is a bit dickey
                   $link = str_replace('index.php', 'index2.php', $tmp->url);
                   $data = '<a href="'.$link.'" onclick="window.open(this.href,\'targetWindow\',\''.$attribs.'\');
                     return false;">'.$image.$tmp->name.'</a>';
                   break;
             }
          } else {
             $data = '<a>'.$image.$tmp->name.'</a>';
          }

          return $data;
          
       }

Login to your admin site and edit a menu item. Now open the "Parameters - System" accordion item on the right and you will see your accesskey parameter. Set a value, save the menu item and voila.