Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved MVC events #37978

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ef1dbec
start
Denitz Jun 4, 2022
ac7525f
fix
Denitz Jun 4, 2022
b6062f9
Deal with custom _getList
Denitz Jun 4, 2022
ab6168f
Make sure a value is passed to base64_decode (#36693)
roland-d Jun 3, 2022
f436ee6
start
Denitz Jun 4, 2022
251cd49
fix
Denitz Jun 4, 2022
7e3b807
Deal with custom _getList
Denitz Jun 4, 2022
8a42514
Merge branch 'MVC_model_events' of github.com:Denitz/joomla-cms into …
Denitz Jun 4, 2022
af4a5ba
Make sure a value is passed to base64_decode (#36693)
roland-d Jun 3, 2022
ea5a9d6
start
Denitz Jun 4, 2022
3adc6a6
fix
Denitz Jun 4, 2022
f2db3b5
Deal with custom _getList
Denitz Jun 4, 2022
4e51834
fix
Denitz Jun 4, 2022
888671a
Deal with custom _getList
Denitz Jun 4, 2022
9944213
Merge branch 'MVC_model_events' of github.com:Denitz/joomla-cms into …
Denitz Jun 4, 2022
84cd3de
Merge branch '4.2-dev' into MVC_model_events
richard67 Jun 4, 2022
b699e7e
Revert InstallController
Denitz Jun 5, 2022
f6f5124
Merge branch 'MVC_model_events' of github.com:Denitz/joomla-cms into …
Denitz Jun 5, 2022
6b4f623
Update libraries/src/Event/Model/AfterGetListEvent.php
Denitz Jun 5, 2022
dcdff2e
Update libraries/src/Event/Model/ListQueryEvent.php
Denitz Jun 5, 2022
b4ed48f
Changes snakes to eventListQuery and eventAfterGetList, ?? usage
Denitz Jun 5, 2022
14fe0aa
Merge branch '4.2-dev' into MVC_model_events
richard67 Jun 7, 2022
1d88b6d
fix
Denitz Jun 7, 2022
e9f9614
Update libraries/src/Event/Model/AfterGetListEvent.php
Denitz Jun 7, 2022
8da20e9
Update libraries/src/Event/Model/ListQueryEvent.php
Denitz Jun 7, 2022
e115712
Merge branch '4.2-dev' into MVC_model_events
Denitz Jun 8, 2022
14b69e5
Update libraries/src/Event/Model/AfterGetListEvent.php
Denitz Jun 13, 2022
d4a4c38
Update libraries/src/Event/Model/ListQueryEvent.php
Denitz Jun 13, 2022
96a5852
Update libraries/src/MVC/Model/ListModel.php
Denitz Jun 13, 2022
a08b506
Update libraries/src/MVC/Model/ListModel.php
Denitz Jun 13, 2022
f2d2b16
Update libraries/src/MVC/Model/ListModel.php
Denitz Jun 13, 2022
02c2aec
Merge branch '4.2-dev' into MVC_model_events
Denitz Jun 13, 2022
56cadaf
Update libraries/src/MVC/Model/ListModel.php
Denitz Jun 13, 2022
fb79554
revert events_map
Denitz Jun 13, 2022
e53b4f0
fix cs
Denitz Jun 13, 2022
1a2c561
Remove onContentListQuery event :(
Denitz Jun 15, 2022
6b4ca76
Merge tag 'psr12anchor' into psr12/merge/37978
joomla-bot Jun 27, 2022
31d5e4e
Phase 1 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
f747cc3
Phase 2 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
a5aa118
Merge tag 'psr12final' into psr12/merge/37978
joomla-bot Jun 27, 2022
8f5219e
Merge branch '4.2-dev' into MVC_model_events
laoneo Jun 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
start
  • Loading branch information
Denitz committed Jun 4, 2022
commit ef1dbecf5aedda2700323908dbf252088d8fc174
77 changes: 77 additions & 0 deletions libraries/src/Event/Model/ListQueryEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
Denitz marked this conversation as resolved.
Show resolved Hide resolved
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\CMS\Event\Model;

\defined('JPATH_PLATFORM') or die;

use BadMethodCallException;
use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\MVC\Model\ListModelInterface;

/**
* Event class for modifying a list query
*
* @since __DEPLOY_VERSION__
*/
class ListQueryEvent extends AbstractEvent
{
/**
* Mandatory arguments:
* subject ListModelInterface The model instance we are operating on.
* context string The model context.
* query QueryInterface Database query.
Denitz marked this conversation as resolved.
Show resolved Hide resolved
*
* @param string $name The event name.
* @param array $arguments The event arguments.
*
* @throws BadMethodCallException
*
* @since __DEPLOY_VERSION__
*/
public function __construct($name, array $arguments = array())
Denitz marked this conversation as resolved.
Show resolved Hide resolved
{
if (!\array_key_exists('subject', $arguments))
{
throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided");
}

if (!\array_key_exists('context', $arguments))
{
throw new BadMethodCallException("Argument 'context' is required for event $name");
}

if (!\array_key_exists('query', $arguments))
{
throw new BadMethodCallException("Argument 'query' is required for event $name");
}

parent::__construct($name, $arguments);
}

/**
* Setter for the subject argument
*
* @param ListModelInterface $value The value to set
*
* @return ListModelInterface
*
* @throws BadMethodCallException If the argument is not of the expected type.
*
* @since __DEPLOY_VERSION__
*/
protected function setSubject($value)
{
if (!\is_object($value) || !($value instanceof ListModelInterface))
{
throw new BadMethodCallException("Argument 'subject' of event {$this->name} is not of the expected type");
}

return $value;
}
}
28 changes: 28 additions & 0 deletions libraries/src/MVC/Model/ListModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
\defined('JPATH_PLATFORM') or die;

use Exception;
use Joomla\CMS\Event\Model\ListQueryEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Form\Form;
Expand Down Expand Up @@ -121,6 +122,14 @@ class ListModel extends BaseDatabaseModel implements FormFactoryAwareInterface,
*/
protected $listForbiddenList = array('select');

/**
* The event to trigger on list query
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $event_list_query;
Denitz marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructor
*
Expand Down Expand Up @@ -157,6 +166,15 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
{
$this->listForbiddenList = array_merge($this->listBlacklist, $this->listForbiddenList);
}

if (isset($config['event_list_query']))
{
$this->event_list_query = $config['event_list_query'];
}
elseif (empty($this->event_list_query))
{
$this->event_list_query = 'onContentListQuery';
}
Denitz marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -216,6 +234,16 @@ protected function _getListQuery()
{
$this->lastQueryStoreId = $currentStoreId;
$this->query = $this->getListQuery();

$event = new ListQueryEvent(
$this->event_list_query,
[
'subject' => $this,
'context' => $this->context,
'query' => $this->query,
Denitz marked this conversation as resolved.
Show resolved Hide resolved
]
);
$this->dispatchEvent($event);
}

return $this->query;
Expand Down