Modifying the menu type

The HelloWorld menu type displays a drop down list of all messages. If the message is categorized, we have to add the category in this display.

In the admin/models/fields/helloworld.php file, put these lines:

admin/models/fields/helloworld.php

<?php// No direct access to this filedefined('_JEXEC') or die;// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');/**
* HelloWorld Form Field class for the HelloWorld component
*/class JFormFieldHelloWorld extends JFormFieldList
{/**
* The field type.
*
* @var string
*/
protected $type='HelloWorld';/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*/
protected function getOptions(){$db= JFactory::getDBO();/// $query = new JDatabaseQuery; WARNING - There's an error in this line, JDatabaseQuery is an abstract class$query=$db->getQuery(true);// THIS IS THE FIX, WARNING IT MUST BE FIXED IN THE ZIP FILES$query->select('#__helloworld.id as id,greeting,#__categories.title as category,catid');$query->from('#__helloworld');$query->leftJoin('#__categories on catid=#__categories.id');$db->setQuery((string)$query);$messages=$db->loadObjectList();$options=array();if($messages){foreach($messagesas$message){$options[]= JHtml::_('select.option',$message->id,$message->greeting.($message->catid ? ' ('.$message->category.')':''));}}$options=array_merge(parent::getOptions(),$options);return$options;}}

It will now display the category between parenthesis.

Managing the submenu

The com_categories component allows to set the submenu using a helper file. With your favorite file manager and editor, put a admin/helpers/helloworld.php file containing these lines:

Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.

helloworld.xml

<?xmlversion="1.0"encoding="utf-8"?><extensiontype="component"version="2.5.0"method="upgrade"><name>COM_HELLOWORLD</name><!-- The following elements are optional and free of formatting constraints --><creationDate>November 2009</creationDate><author>John Doe</author><authorEmail>john.doe@example.org</authorEmail><authorUrl>http://www.example.org</authorUrl><copyright>Copyright Info</copyright><license>License Info</license><!-- The version string is recorded in the components table --><version>0.0.12</version><!-- The description is optional and defaults to the name --><description>COM_HELLOWORLD_DESCRIPTION</description><install><!-- Runs on install --><sql><filedriver="mysql"charset="utf8">sql/install.mysql.utf8.sql</file></sql></install><uninstall><!-- Runs on uninstall --><sql><filedriver="mysql"charset="utf8">sql/uninstall.mysql.utf8.sql</file></sql></uninstall><update><!-- Runs on update; New in 2.5 --><schemas><schemapathtype="mysql">sql/updates/mysql</schemapath></schemas></update><!-- Site Main File Copy Section --><!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /site/ in the package --><filesfolder="site"><filename>index.html</filename><filename>helloworld.php</filename><filename>controller.php</filename><folder>views</folder><folder>models</folder><folder>language</folder></files><mediadestination="com_helloworld"folder="media"><filename>index.html</filename><folder>images</folder></media><administration><!-- Administration Menu Section --><menuimg="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</menu><!-- Administration Main File Copy Section --><!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /admin/ in the package --><filesfolder="admin"><!-- Admin Main File Copy Section --><filename>index.html</filename><filename>helloworld.php</filename><filename>controller.php</filename><!-- SQL files section --><folder>sql</folder><!-- tables files section --><folder>tables</folder><!-- models files section --><folder>models</folder><!-- views files section --><folder>views</folder><!-- controllers files section --><folder>controllers</folder><!-- helpers files section --><folder>helpers</folder></files><languagesfolder="admin"><languagetag="en-GB">language/en-GB/en-GB.com_helloworld.ini</language><languagetag="en-GB">language/en-GB/en-GB.com_helloworld.sys.ini</language></languages></administration></extension>