yag GalleryHideFilter

As yag is mainly based on pt_extlist, which is a generic extension for rendering all sorts of lists within TYPO3, there are som "hidden" features, each yag extension comes with. One of those features is the ability of configuring arbitrary filters on your own and easily add them to the chain of filters, that yag - pt_extlist respectively - uses, when showing a list of elements.

One of those lists contains the galleries presented to the user if plugin mode "Gallery List" is used. Some of you will probably have noticed a directory "Classes/Extlist/Filter" within your yag extension directory. That's where we recently put another filter that enables users to select which galleries to display using some TypoScript configuration.

Assume you have a lot of galleries on a big site. Probably you have a page like "Gallery" there, where you want to display all galleries except some of them which you use as a container for galleries to be shown only on certain pages - like a blog for example. Then you could use this filter to hide the "special" galleries on your Gallery overview page.

There are actually 2 settings allowed for this filter: 1. Set up a comma-separated list of UIDs that should be shown exclusively. 2. Set up a comma-separated list of UIDs that should NOT be shown.

Writing your own filters / filter-extensions for yag Gallery

So after this documentation on how to use the gallery filter, let's take a look on how filters work in yag. To get a full-explanation on how to write filters for pt_extlist, please refer to pt_extlist documentation. We will cover only the yag-relevant parts here.

First of all, each filter has its own class handling some kind of filter-input (like a user-input in a html form field, or a TypoScript setting as we have it in our case), the constraints created for the pt_extlist data backend and some other stuff. You can find the filter classes shipping with yag in the "Classes/Extlist/Filters" directory of yag.

Now let's take a look at the "galleryUid" filter to see how it works: The relevant method here is "buildFilterCriteriaForAllFields":

In line 7, we get our TS configuration from the so-called filter configuration object. Configuration objects are objects to capsulate TypoScript settings in an object notation. You can always get the "raw TS settings" with the getSettings() method. As an argument, it takes the TS-key within the relevant section of the TypoScript configuration. So here, we want to get the "onlyInUids" value.

We then explode the comma-seperated list of UIDs and create what is called a filter criteria in line 11. A filter criteria is kind of a generic constraint for queries made with an arbitrary data source. In our case, we later translate the constraint to a Extbase query object to get our data from the repository. Abstracting the query from a concrete syntax (e.g. Extbase or SQL) enables us to use different backends and a corresponding query language. So perhaps one day, we will have doctrine here...

The second if-block starting in line 17 does the same for the 'notInUids' setting.

Fazit

This tutorial shows how to use and create your own filters for yag. You can write much more complex filters involving user input. We think that using pt_extlist as a basis for our lists is what makes yag so powerful when it comes to filtering its contents. If you think you wrote a filter that could be useful for other users too, share it on yag project page on forge.typo3.org.