onContentAfterListQuery event ?

35 views
Skip to first unread message

Lucas Sanner

unread,
Apr 26, 2018, 8:44:52 AM4/26/18
to Joomla! Framework Development
Hi,

In my components I very often use plugins to handle the various trigger events sent by the Joomla framework all along the several workflows as save, delete etc..
It's a powerfull and clean way to achieve my aims without using dirty hacks. 
However, a trigger event which allow to override list queries is sorely lacking. 
It would be great to modify some component's queries whenever it's needed.
Such trigger is actually pretty easy to implement in the Joomla library.

In the libraries/src/MVC/Model/ListModel.php file at the end of the _getListQuery() function, just add the following:
protected function _getListQuery()
{
  ...

  \JPluginHelper::importPlugin('content');
  $dispatcher = \JEventDispatcher::getInstance();
  $dispatcher->trigger('onContentAfterListQuery', array($this->context, $this->query));

  return $this->query;
}

Then you just have to handle the event in your content plugin:

public function onContentAfterListQuery($context, $query)
{          
   //Do whatever you want here...
}

Would it be possible to add this trigger event in a future Joomla version ?
Where can I submit this proposal ?

Thanks

Michael Babker

unread,
Apr 26, 2018, 10:07:07 AM4/26/18
to joomla-dev...@googlegroups.com
Proposals to add plugin events allowing query manipulation have been shot down pretty hard over the years and really aren't a good practice to accept.

--
Framework source code: https://github.com/joomla-framework
Visit http://developer.joomla.org for more information about developing with Joomla!
---
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-framework+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-framework.

Reply all
Reply to author
Forward
0 new messages