We started a new project, a website that lists products based on regions (for example US and Europe). We have all products in 1 channel (to make it dynamic to add more regions later on) and have a region field added to those entries (a checkbox field). We now want to hide products for specific users in the CP.
Through this thread I was able to add custom permissions via my plugin and it pointed me towards this event onBeforeBuildElementsQuery that I could use to add my custom filtering. I think I may need to add a custom param with the value of what the regio field needs to be to the ElementCriteriaModel.
But I have no idea how to build the next steps. I don't really understand what that ElementCriteriaModel returns. It's just a model with all basic attributes, no custom fields or anything. No clear section it targets...
The next steps should be:
- Is the event triggered by the CP?
- If so, check the logged in user's permissions and decide what regio should be filtered
- Add an extra param to the criteria that filters to correct region
- Send the changed ElementCriterioModel (or Query) to wherever it needs to go
So, how do I insert a custom parameter into that ElementCriteriaModel and will it alter the entries that are visible in the CP? Am I on the right track here?