zfcampus/zf-content-validation

Custom Filters (Enhancement)

spectravp opened this issue · 5 comments

I have two repo's (filters and validators) that I typically add to projects via composer. With my validators repo, I have a config file with the key of 'validator_metadata'. The great thing about this is that I make my validator repo a dependency and all my custom validators are now available in the apigility admin, complete with options. I don't have to manually add/configure my custom validators into the apigility generated config file.

But the same can't be said for filters using the key of 'filter_metadata'. I understand filters are composed differently than validators, but it would be great to be able to add custom filters in the same manner.

This actually does work, and I know I've used the feature myself.

If you look at the admin's FiltersModelFactory, it pulls the filter_metadata from the configuration object -- which is the result of merging all module configurations -- to seed the FiltersModel. The format for that structure is exactly the same as for validators.

In both cases, the filters and validators shown are those present in their respective plugin managers -- and that's what populates the dropdown list. Are you sure you're registering your filters with the FilterManager?

Thanks, Matt. So you are saying that I can't simply add the filters config, but I also must register them via the FilterManager?

Upon further inspection, my filters are in the config passed to the FilterModelFactory, which appears to be registering all the filter with the plugin manager. What am I missing here?

@spectravp what is the FilterModelFactory? They need to be registered with the FilterManager... in other words, via the filters configuration, or via a getFilterConfig() method in your module. (configuration will be the same format as for the service manager)

Once again, Matthew, you prove to be a god. :-) Thank you for your help, but most importantly, your patience. Much appreciated.