Hello,
I've brought this up internally several weeks ago, but since nothing has
happened, I'm bringing this up here too.
Please improve the code quality of the custom fields feature. I only
looked through JFormField and see loads of problems. So far, Joomla has
always tried to use understandable and sane method names and where
ambigious, we have extensive comments. We also normally have unittests.
This is currently not the case for at least JFormField for the fields
feature and I've seen equally poor code in other PRs.
To give you an example what is wrong with JFormField:
The last method of the class is named "getFormParameters", however that
seems to return an XML for this field. So at least name it
getFieldParameters and I would actually call it getFieldForm, since that
is what it does. The code itself uses some horrible reflection stuff to
get the directory of the original class file, which means that there is
no way to override that field form file completely. Why can't we use
something like the JFormHelper class with all the paths to lookup in?
Also, why can't we simply use the lowercase JFormField::$type of the
field to find the filename? Then it uses JFile::exists(), which our own
documentation says to use file_exists() instead, just to then use
JFile::read(), which the same documentation says to use
file_get_contents() instead.
The next method is named postProcessDomNode and looking at that, I have
no idea at all what that method is supposed to do. So I read the doc
block ... and am no wiser. The doc block is completely useless. The
method otherwise is empty.
The next method has an equally non-sensical name (appendXMLFieldTag) and
again the doc block has VERY little information. At least a little bit
more than the other method. Looking through this code, I first stumble
over a call to JFactory::getApplication() and checks against some
parameter and isSite() and isAdmin(). I don't think that a class like
JformField should be tied to JApplicationCms like this. Anyway... Then
there is some more code that I don't really want to review and at the
end we have a call to postProcessDomNode(). And I'm asking myself why we
have to have this postProcessDomNode() method at all. What is wrong with
overriding appendXMLFieldTag() and doing something like
public function appendXMLFieldTag() {
$node = parent::appendXMLFieldTag();
/** Do magic **/
return $node;
}
So we could simply drop the postProcessDomNode() method, since it is
completely useless.
This code does not raise confidence in this feature from me. We are
introducing a new feature here and with the active opposition of moving
to Joomla 4.0 soon AND the REALLY bad press we would get if we
introduced this here now and then completely rewrote it in 4.0 again,
breaking everyones code, we should get this right the first time. We are
stuck with the method names the moment we release this as a stable
release. Considering that we are still trying to get rid of methodnames
and attributes introduced in Joomla 1.5 (and been doing so since Joomla
1.6), this is extremely important! As I wrote a few weeks ago, I also
expect a feature like this to be covered by unittests and I refuse to
accept the explanation "Oh, we don't require unittests here, because
people don't know how to write them." If that is the case, then don't
put this code in the /libraries folder. Then you can also just rewrite
it whenever you want and actually simply provide it as a non-core
extension until it is ready for core. Writing unittests is no magic and
can be learned. But simply adding new code without tests is a sure way
for us to mess this up even more. (I would have used a different word
than "mess" but apparently there are very sensitive souls on this
mailinglist...) If unittests are such a big issue, we should rather
simply drop our testsuite and and not require any tests at all, since if
half the code can be added without tests, I don't see why I have to
waste my time writing such tests.
If we accept new features and new code into Joomla, it has to be done
properly and the code has to be usable AND serviceable by other people.
More fiaskos like with Tags or Finder are unacceptable.
Regards,
Hannes