Monday, 10 January 2011

Writing an admin backend for a Joomla! component

I wanted to add an admin back-end to my mvd-gui component. There are few instructions about how to do this and all of them are messy. Basically you are supposed to define a model-view-controller interface as in the site part of the component. But in the Joomla application they have shortcuts that only require a few lines of code, so I wanted to do it that way. Also it would look more consistent and reformat properly when the user changed the admin template.

So I took the massemail component's admin interface, which was quite simple, and deconstructed it. Customising the icons that appear in the toolbar was easy: just modify the calls to JToolBarHelper in toolbar.massemail.html.php. (You should rename this file as something else). I then got stuck on changing the icon that is displayed in the toolbar. Basically you call JToolBarHelper::title with 2 arguments: the first is the text you want displayed. The 2nd argument is supposed to be an image, but in reality it has to be one of the images in the images directory of the admin template. Since I can't add to that without making my changes non-portable I decided just to use the generic icon. It looks OK:

Or, in code-form:

class TOOLBAR_mvdcore
{
 /**
 * Draws the menu for a New Contact
 */
 function _DEFAULT() {
  JToolBarHelper::title( 'mvd-core', 'generic.png' );
  JToolBarHelper::cancel();
  JToolBarHelper::save();
  JToolBarHelper::help( 'screen.users.massmail' );
 }

Next step is to supply a help file. That's the last line in the code above. Then I still have to provide code for the save button and reformat the HTML form so that it displays my stuff. I'll save that for tomorrow's post.

3 comments:

  1. I am also struggling on one of my joomla component code.I never knew that in the Joomla application they have shortcuts that only require a few lines of code.I am surely going to try the steps you gave in hope I'll be successful.Thanks.
    electronic signature

    ReplyDelete
  2. It’s good to see this information in your post, I was looking the same but there was not any proper resource, thanks now I Thank to the post.I really loved reading your blog.It was very well authored and easy to understand.
    joomla extensions

    ReplyDelete