Overriding form fields

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
andypooz
Joomla! Guru
Joomla! Guru
Posts: 728
Joined: Sat Dec 30, 2006 3:03 pm
Location: London, UK
Contact:

Overriding form fields

Post by andypooz » Sat Feb 10, 2018 1:39 pm

I recently needed to add the ability to filter the category form field type to only take categories with a certain parent category.

I've working, but I wanted to see what people advised in terms of not hacking. My approach (for simplicity more than anything else) was to create two new files
libraries/cms/html/filteredcategory.php
libraries/legacy/form/field/filteredcategory.php

and largely duplicate the category.php file in each case and add a new parameter to the new method which adds a 'where' condition to the query, and a new parent="10" to the form's xml file to call it.

It all works fine, but I just wanted to know if there's a better approach. I could have put the custom field into the component directory, but am I right in thinking that because I haven't edited any core file, but rather added new ones to the core directories, that these will survive updates?

I'd like to be able to use this in some of my other projects- any way to get this into a plugin?

In this use case, I actually have a few different sets of categories I'd like to use in my component, so I've separated them into sub categories to achieve this, but they really don't belong together- they're chalk and cheese, even if they are used by the same category.

nb. I realise I'm not 'overriding' these fields but creating new ones, maybe overriding is a better approach (although not sure how I'd do that)?
Andy Hickey
Bespoke Joomla Extension Developer
http://www.netamity.com

Locked

Return to “Joomla! 3.x Coding”