Skip to content

Commit 96c6887

Browse files
authored
[5.3] [Events] Use event classes for Sampledata plugins (#43636)
* SampleData Event * SampleData testing * SampleData multilang * SampleData blog
1 parent c6158f4 commit 96c6887

File tree

6 files changed

+415
-148
lines changed

6 files changed

+415
-148
lines changed

libraries/src/Event/CoreEventAware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ trait CoreEventAware
203203
'onPageCacheSetCaching' => PageCache\SetCachingEvent::class,
204204
'onPageCacheGetKey' => PageCache\GetKeyEvent::class,
205205
'onPageCacheIsExcluded' => PageCache\IsExcludedEvent::class,
206+
// Sample Data
207+
'onSampledataGetOverview' => SampleData\GetOverviewEvent::class,
206208
// Mail
207209
'onMailBeforeRendering' => Mail\BeforeRenderingMailTemplateEvent::class,
208210
];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Event\SampleData;
11+
12+
use Joomla\CMS\Event\Result\ResultAware;
13+
use Joomla\CMS\Event\Result\ResultAwareInterface;
14+
use Joomla\CMS\Event\Result\ResultTypeObjectAware;
15+
16+
// phpcs:disable PSR1.Files.SideEffects
17+
\defined('_JEXEC') or die;
18+
// phpcs:enable PSR1.Files.SideEffects
19+
20+
/**
21+
* Cass for Sample data events
22+
*
23+
* @since __DEPLOY_VERSION__
24+
*/
25+
class GetOverviewEvent extends SampleDataEvent implements ResultAwareInterface
26+
{
27+
use ResultAware;
28+
use ResultTypeObjectAware;
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Event\SampleData;
11+
12+
use Joomla\CMS\Event\AbstractImmutableEvent;
13+
14+
// phpcs:disable PSR1.Files.SideEffects
15+
\defined('_JEXEC') or die;
16+
// phpcs:enable PSR1.Files.SideEffects
17+
18+
/**
19+
* Base class for Sample data events
20+
*
21+
* @since __DEPLOY_VERSION__
22+
*/
23+
abstract class SampleDataEvent extends AbstractImmutableEvent
24+
{
25+
/**
26+
* Constructor.
27+
*
28+
* @param string $name The event name.
29+
* @param array $arguments The event arguments.
30+
*
31+
* @throws \BadMethodCallException
32+
*
33+
* @since __DEPLOY_VERSION__
34+
*/
35+
public function __construct($name, array $arguments = [])
36+
{
37+
parent::__construct($name, $arguments);
38+
39+
if (!\array_key_exists('subject', $this->arguments)) {
40+
throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided");
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)