Joomla – Editing “Advanced Attribs” from Front end

I have run into a project that requires attaching some addition “Advanced” attributes to Joomla articles.

I have extended the “blog category” menu type to incorporate jQuery to display the blog category with the titles as vertical tabs, and the introtext displayed in a content div when each tab is clicked.

Articles selected for this vertical tabbed menu will also have an associated “menu image” and a “video file”.  The menu image will be a thumbnail that gets displayed in the tab, and the video file will be a flv video that is used to populate (using javascript) a fixed video player that will appear in another module position on the website.

Note – this requires hacking a few Joomla core files.  This coding was done on a Joomla 1.5.14 install.  Joomal updates may break this code, depending on what gets updated. After installing these hacks, I would recommend making a backup of the modified files in case future Joomla upgrades overwrite these changes.

Disclaimer: Use this code at your own  risk – I am not responsible for any breakage of your Joomla website.

First, to add the items in the “Parameters (Advanced)” area of the back end edit page, some tweaks need to be made to the file administrator/components/com_content/models/article.xml.  As always, make sure to make a backup of all files before editing them.

Locate the line :     <params group=”advanced”> and right below it add :

<param name=”article_image” type=”imagelist” directory=”/images/stories/thumbs” default=”” label=”Menu Image” description=”Select the image to appear in the menu” />
<param name=”article_video” type=”filelist” directory=”/images/stories/videos” default=”” label=”Video File” description=”Select the video file for this article” />

Each <param> line should appear on a single line.  Here is what the options mean:

name=”article_image”
— pretty self explainatory  – the param name – that appears in the attribs section of the db record

type=”imagelist”
directory=”/images/stories/thumbs”
— This defines what type of field will appear.  I found a good reference to the different field types here.  imagelist will show only images found in the directory.  filelist will show all files in the directory.

default=””
— the default value set on the select drop down

label=”Menu Image”
— this is the name shown in the html form

description=”Select the image to appear in the menu”
— this is the mouse over tooltip

The website owner will need to manage all the content from the frontend – so we also need to place a modified copy of article.xml in components/com_content/models/.  For this copy of the file, you can delete the first and last <params> block, just leaving the “advanced” group.  Now, for the front end, I don’t want the site owner to make changes to anything but the 2 new fields, so I change each “type” field to “hidden“.  The values will still get set and appear as hidden form fields.  If you want the site owner to be able to toggle on things like the print icon, email icon, etc … you can leave those be.

The next step requires setting up a template override. You will need to place a copy of components/com_content/views/article/tmpl/form.php in templates/–yourtemplate–/html/com_content/article/  (create the directory if it does nometat exist).  I decided to drop the added fields in the Metadata area of the front end form. To do this, open the form.php file, find the last </fieldset> near the bottom, and add :

<?php
//Load the modified copy of article.xml
$form = new JParameter(”, JPATH_COMPONENT.DS.’models’.DS.’article.xml’);

// preload the current article values
$form->loadINI($this->article->attribs);

//dump it to the screen
echo $form->render(‘params’, ‘advanced’);
?>

Now, if you open a page in the front end edit mode, you should see the additional parameters down below the Meta tags and keywords.

The real problem was actually saving these extra field forms.  This is where it really required a hack to the main Joomla source.  After making a backup copy, open components/com_content/models/article.php in your favorite editor. Around line 400 (in Joomla 1.5.14) find the line :

$article->version++;

Below this line add the following code snippet (from the admin area) :

// pull in the parameters from the form
$params     = JRequest::getVar( ‘params’, null, ‘post’, ‘array’ );
// Build parameter INI string
if (is_array($params))  {
$txt = array ();
foreach ($params as $k => $v) {

$txt[] = “$k=$v”;
}
// add this to the article object.
$article->attribs = implode(“n”, $txt);
}

One thought on “Joomla – Editing “Advanced Attribs” from Front end

  1. hi, thanks for your help, you solved a problem for me!
    however I want to warn that there are 2 small mistakes.
    I write down just for code dummies like me 🙂

    in the override of the template code should be
    $form = new JParameter(”, JPATH_COMPONENT.DS.’models’.DS.’article.xml’);
    quotation marks has been inserted instead of superscript

    in modifing article.php you forgot a slash
    $article->attribs = implode(“\n”, $txt);

Leave a Reply

Your email address will not be published.