Sunday, 1 August 2010

Custom image folder for Joomla Contacts

Because my church web site has a large number of contacts, I wanted to put all the photos in their own folder. Joomla's Contacts component normally expects photos to be stored at the default image location, /images/stories. I have a folder named portraits under this folder, but Joomla doesn't recurse into it when you select an image in the contact form.

It turns out that you have to make only three small edits to get this working, but I spent a frustrating few hours investigating before I found out how. To save you the trouble, here's the recipe. All file paths are relative to the Joomla root.

  1. Edit /components/com_contact/views/contact/tmpl/default.php. On line 52, change
    <?php echo JHTML::_('image', 'images/stories' . '/'.$this->contact->image, ...
    <?php echo JHTML::_('image', 'images/stories/portraits' . '/'.$this->contact->image, ...
  2. Edit /administrator/components/com_contact/ On line 227, change
    $lists['image'] = JHTML::_('list.images', 'image', $row->image );
    $lists['image'] = JHTML::_('list.images', 'image', $row->image, NULL, '/images/stories/portraits/' );
  3. Edit /administrator/components/com_contact/ On line 437, change
    jsimg='../<?php echo $cparams->get('image_path'); ?>/' + ...
    jsimg='../<?php echo $cparams->get('image_path'); ?>/portraits/' + ...

Afterwards, you will have to open each contact you've previously created and select the portrait anew. I did try doing a bulk edit by exporting the contacts table to CSV and globally replacing, but that was a dismal failure.

The Joomla maintainers are apparently part way through parameterising the location of the stories folder (see the call to get('image_path') above). Ideally the location of the portraits would be a separate parameter. I didn't have time to do this, but this investigation clearly reveals the places where the parameter would need to be used.


Fuad said...

Dear sir
I followed your comments and instructions but then when adding a new contact... a red line showed up saying.. JFolder::files: Path is not a folder
and had a :-
Warning: Invalid argument supplied for foreach() in /home1/xyz/public_html/xyz/libraries/joomla/html/html/list.php on line 62

Immo Hüneke said...

I expect the foreach argument was invalid because the directory did not exist or was empty. It might work if you created the portraits folder under images and placed some jpeg images in it.

Daniel A. Acevedo V. said...

Hi, it works for me, but in the Contact View the path doesnt change :( any idea? BTW, Thank you for the post

Harley Watts said...

custom software development