Skip to content

Commit 56a4640

Browse files
authored
[5.2][Events] Use event classes for Media-action plugins (joomla#43608)
1 parent 5147b27 commit 56a4640

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

administrator/components/com_media/src/Plugin/MediaActionPlugin.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Joomla\Component\Media\Administrator\Plugin;
1212

13+
use Joomla\CMS\Event\Model\PrepareFormEvent;
1314
use Joomla\CMS\Form\Form;
1415
use Joomla\CMS\HTML\HTMLHelper;
1516
use Joomla\CMS\Plugin\CMSPlugin;
@@ -34,6 +35,35 @@ class MediaActionPlugin extends CMSPlugin
3435
*/
3536
protected $autoloadLanguage = true;
3637

38+
/**
39+
* Returns an array of events this subscriber will listen to.
40+
*
41+
* @return array
42+
*
43+
* @since __DEPLOY_VERSION__
44+
*/
45+
public static function getSubscribedEvents(): array
46+
{
47+
return [
48+
'onContentPrepareForm' => 'onContentPrepareFormListener',
49+
];
50+
}
51+
52+
/**
53+
* The form event. Load additional parameters when available into the field form.
54+
* Only when the type of the form is of interest.
55+
*
56+
* @param PrepareFormEvent $event Event instance.
57+
*
58+
* @return void
59+
*
60+
* @since __DEPLOY_VERSION__
61+
*/
62+
public function onContentPrepareFormListener(PrepareFormEvent $event): void
63+
{
64+
$this->onContentPrepareForm($event->getForm(), $event->getData());
65+
}
66+
3767
/**
3868
* The form event. Load additional parameters when available into the field form.
3969
* Only when the type of the form is of interest.

plugins/media-action/crop/src/Extension/Crop.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Joomla\CMS\Application\CMSWebApplicationInterface;
1414
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
15+
use Joomla\Event\SubscriberInterface;
1516

1617
// phpcs:disable PSR1.Files.SideEffects
1718
\defined('_JEXEC') or die;
@@ -22,7 +23,7 @@
2223
*
2324
* @since 4.0.0
2425
*/
25-
final class Crop extends MediaActionPlugin
26+
final class Crop extends MediaActionPlugin implements SubscriberInterface
2627
{
2728
/**
2829
* Load the javascript files of the plugin.

plugins/media-action/resize/src/Extension/Resize.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
namespace Joomla\Plugin\MediaAction\Resize\Extension;
1212

13+
use Joomla\CMS\Event\Model\BeforeSaveEvent;
1314
use Joomla\CMS\Image\Image;
1415
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
16+
use Joomla\Event\SubscriberInterface;
1517

1618
// phpcs:disable PSR1.Files.SideEffects
1719
\defined('_JEXEC') or die;
@@ -22,22 +24,36 @@
2224
*
2325
* @since 4.0.0
2426
*/
25-
final class Resize extends MediaActionPlugin
27+
final class Resize extends MediaActionPlugin implements SubscriberInterface
2628
{
29+
/**
30+
* Returns an array of events this subscriber will listen to.
31+
*
32+
* @return array
33+
*
34+
* @since __DEPLOY_VERSION__
35+
*/
36+
public static function getSubscribedEvents(): array
37+
{
38+
return array_merge(parent::getSubscribedEvents(), [
39+
'onContentBeforeSave' => 'onContentBeforeSave',
40+
]);
41+
}
42+
2743
/**
2844
* The save event.
2945
*
30-
* @param string $context The context
31-
* @param object $item The item
32-
* @param boolean $isNew Is new item
33-
* @param array $data The validated data
46+
* @param BeforeSaveEvent $event The event instance
3447
*
3548
* @return void
3649
*
3750
* @since 4.0.0
3851
*/
39-
public function onContentBeforeSave($context, $item, $isNew, $data = [])
52+
public function onContentBeforeSave(BeforeSaveEvent $event): void
4053
{
54+
$context = $event->getContext();
55+
$item = $event->getItem();
56+
4157
if ($context != 'com_media.file') {
4258
return;
4359
}

plugins/media-action/rotate/src/Extension/Rotate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Joomla\Plugin\MediaAction\Rotate\Extension;
1212

1313
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
14+
use Joomla\Event\SubscriberInterface;
1415

1516
// phpcs:disable PSR1.Files.SideEffects
1617
\defined('_JEXEC') or die;
@@ -21,6 +22,6 @@
2122
*
2223
* @since 4.0.0
2324
*/
24-
final class Rotate extends MediaActionPlugin
25+
final class Rotate extends MediaActionPlugin implements SubscriberInterface
2526
{
2627
}

0 commit comments

Comments
 (0)