Feature No Code Attached Yet
avatar pe7er
pe7er
28 May 2024

Joomla components use Models to fetch data (like articles) from the database. We would like to introduce two new Plugin Events in component models, which allows you to tweak queries using plugins.

If you want to change the query of for instance the front-end ArticlesModel, then you can't.
Or you have to use a cumbersome workaround: create a system plugin that loads your own changed copy of the ArticlesModel before Joomla does. However, such a "model override" is difficult and there's no option like with Template Overrides to see if there are any changes in the Joomla core model after Joomla updates.

Therefore we would like to have two new plugin events where you can hook into the filtering and into the query of the Model to modify the query.

Use case

com_content - back-end

In the back-end via Content > Articles you get an overview of all articles.
If you want to add an extra column to display the intro image of an article, you can create a template override.
However, the "images" field that contains the "intro_image" is not in the query to retrieve the articles.
Add a database query in the template override is not the right way, and might slow down the page.
And if you want to add an extra filter in the override (e.g. to filter images on (non) availability of the intro image), then you can't.

It would be handy to have two new plugin events in /administrator/components/com_content/src/Model/ArticlesModel.php in the methods:

  • populateState()
  • getListQuery()

With new plugin events in those methods, you could hook into them.
And have your plugin add new filters and extra queries to the $query object.

com_content - front-end

The front-end Category Blog loads all articles from a specific category.
With new plugin events you can have your own plugins modify the query to add or remove items from the list.

It would be handy to have two new plugin events in
In /components/com_content/src/Model/CategoryModel.php

  • populateState()
  • getItems()

With new plugin events in those methods, you could hook into them.
And have your plugin add new filters and extra queries to the $query object.

avatar pe7er pe7er - open - 28 May 2024
avatar joomla-cms-bot joomla-cms-bot - change - 28 May 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 May 2024
avatar pe7er pe7er - change - 28 May 2024
Labels Added: Feature
avatar pe7er pe7er - labeled - 28 May 2024
avatar pe7er pe7er - change - 28 May 2024
The description was changed
avatar pe7er pe7er - edited - 28 May 2024
avatar rdeutz
rdeutz - comment - 1 Jun 2024

Just to get it not wrong, you want this for all models and not only for com_content?

avatar HLeithner
HLeithner - comment - 1 Jun 2024

There is a reason we don't have this, don't have the time to find the relevant issues here in github but we have several of them. One of the things is our database schema is not part of the b/c policy.

avatar pe7er
pe7er - comment - 8 Jun 2024

Just to get it not wrong, you want this for all models and not only for com_content?

First in com_content, later maybe in other models as well.

avatar wilsonge
wilsonge - comment - 12 Jun 2024

This dates back a looooong way https://groups.google.com/g/joomla-dev-cms/c/KkGuhBYvoyo/m/sTILTLIqfXIJ

But for all the reasons. This quickly decents into plugin per database query. The performance is bad. The chance of database queries stepping over each other is high. I'm very against this.

Especially the removing of items. That's why it's a bad idea!

avatar brianteeman
brianteeman - comment - 12 Jun 2024

Thanks for sharing that link @wilsonge - my main takeaway from all of that was this from Andrew

But more than than, ad hoc altering of a query is a dangerous practice to move forward with (testability, introducing slow queries, bad joins, changing physical behaviour of the original query, collisions on the same query from two developers, etc and so on)

I don't see anything that has changed in Joomla, Extension Developer practices, or this proposal that changes this

avatar rdeutz rdeutz - change - 12 Jun 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-06-12 18:04:48
Closed_By rdeutz
avatar rdeutz rdeutz - close - 12 Jun 2024
avatar pe7er
pe7er - comment - 13 Jun 2024

This possible future feature has been discussed in yesterday's weekly CMS Maintenance meeting.
However, it was decided that the feature could be too risky, potentially causing numerous issues if multiple plugins would run simultaneously and change the queries.

Add a Comment

Login with GitHub to post a comment