Success

User tests: Successful: Unsuccessful:

avatar piotrmocko
piotrmocko
23 Jan 2014

Filter attribute has to be set before field is setup. Otherwise filter would not be used and there are all files from folder in a drop-down

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33183

avatar piotrmocko piotrmocko - open - 23 Jan 2014
avatar infograf768
infograf768 - comment - 23 Jan 2014

Travis fails
.PHP Fatal error: Call to a member function addAttribute() on a non-object in /home/travis/build/joomla/joomla-cms/libraries/joomla/form/fields/imagelist.php on line 53

avatar piotrmocko piotrmocko - change - 23 Jan 2014
The description was changed
Description <p>Filter attribute has to be set before field is setup. Otherwise filter would not be used and there are all files from folder in a drop-down</p> <p>Filter attribute has to be set before field is setup. Otherwise filter would not be used and there are all files from folder in a drop-down</p> <p><a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=33183">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=33183</a></p>
avatar piotrmocko
piotrmocko - comment - 23 Jan 2014

Just fixed, also on Tracker

avatar Bakual
Bakual - comment - 23 Jan 2014

It's actually much easier. Just change the getOptions method to

    protected function getOptions()
    {
        // Define the image file type filter.
        $this->filter = '\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$|\.jpeg$|\.psd$|\.eps$';

        // Get the field options.
        return parent::getOptions();
    }

No need to do anything in the setup method.

Note that instead of using $this->element->addAttribute() the filter is just directly assigned to $this->filter

avatar piotrmocko
piotrmocko - comment - 23 Jan 2014

Yes, it would also work, but I like much better to setup field with correct filter

avatar Bakual
Bakual - comment - 23 Jan 2014

Keep in mind that the formfield may be extended by 3rd party extensions and this could possibly break them depending on what they do with it. Not likely, but still possible imho.

avatar piotrmocko
piotrmocko - comment - 23 Jan 2014

Both approach can break. If someone would redeclare filter in XML or set in setup method, then your case would also override filter

avatar Bakual
Bakual - comment - 23 Jan 2014

If someone would redeclare filter in XML or set in setup method, then your case would also override filter

The imagelist never supported setting the filter in the XML. It's meant to be hardcoded. If you want to set the filter, you use the filelist formfield instead.
You have to make the PR so that it can't break anything, otherwise it can't be merged.

avatar piotrmocko
piotrmocko - comment - 23 Jan 2014

Could you give an example how it could breaks something, because I do not see that.
I Just set attribute filter before parent FileList field would setup it.

avatar Bakual
Bakual - comment - 23 Jan 2014

Actually, it behaves completely wrong currently and still will partially after your patch.
The imagelist field is supposed to show a list of images with a hardcoded file extension list. Currently, it shows everything except if you provide the filter in the XML (which will trigger a PHP warning). This are basically two bugs.
You are fixing the first one but still allow to set a custom filter, which is still a wrong behavior.

Could you give an example how it could breaks something, because I do not see that.

I don't know an example, but I know people tend to do crazy stuff :smile:
If there is no reason to even potentially break something, don't do it. Why would we want to move the call to another place? We need the filter in the getOptions method and only there and it was there since a long time.

avatar piotrmocko
piotrmocko - comment - 23 Jan 2014

I have get back to your suggestion which was also my first try before I submitted PR.

avatar infograf768 infograf768 - change - 29 Jan 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-01-29 16:23:27
Labels Added: ?
avatar infograf768 infograf768 - close - 29 Jan 2014
avatar infograf768 infograf768 - reference | 137a73c - 29 Jan 14
avatar infograf768 infograf768 - merge - 29 Jan 2014
avatar infograf768 infograf768 - close - 29 Jan 2014
avatar piotrmocko piotrmocko - head_ref_deleted - 29 Jan 2014
avatar Bakual Bakual - reference | aca54a3 - 12 May 14

Add a Comment

Login with GitHub to post a comment