Where to define a filter function for a form field in my Joomla component's preferences
Posted
by
Herman
on Stack Overflow
See other posts from Stack Overflow
or by Herman
Published on 2013-11-11T09:44:19Z
Indexed on
2013/11/11
9:53 UTC
Read the original article
Hit count: 217
I am creating a component in Joomla 2.5. This component has some options that are defined in its config.xml, so they can be set in the preferences of the component. Now I would like to apply a filter to one of these option fields, using the attribute filter="my_filter"
.
In the source code of JForm I saw the following lines at the very end of the implementation of JForm::filterField()
:
if (strpos($filter, '::') !== false && is_callable(explode('::', $filter)))
{
$return = call_user_func(explode('::', $filter), $value);
}
elseif (function_exists($filter))
{
$return = call_user_func($filter, $value);
}
That's what I needed for using a filter function defined by myself!
I managed to do this for form fields used in the views of my component. I defined the filter function as MyComponentHelper::my_filter()
, where MyComponentHelper
is a helper class which I always load in the very base of my component. And in the form's xml I added filter="MyComponentHelper::my_filter"
to the fields that have to be filtered. However... when I am trying to apply the filter function to a form field in my component's preferences, I am not in my own component, but in com_config instead, so my helper class is not available!
So, therefore, my question: where to define my own filter function in such a way that it can be found and called by JForm::filterField()
in com_config?? Help is very much appreciated.
© Stack Overflow or respective owner