1111namespace Joomla \Plugin \Content \Finder \Extension ;
1212
1313use Joomla \CMS \Event \Finder as FinderEvent ;
14+ use Joomla \CMS \Event \Model ;
1415use Joomla \CMS \Plugin \CMSPlugin ;
1516use Joomla \CMS \Plugin \PluginHelper ;
17+ use Joomla \Event \SubscriberInterface ;
1618
1719// phpcs:disable PSR1.Files.SideEffects
1820\defined ('_JEXEC ' ) or die;
2325 *
2426 * @since 2.5
2527 */
26- final class Finder extends CMSPlugin
28+ final class Finder extends CMSPlugin implements SubscriberInterface
2729{
2830 /**
2931 * Flag to check whether finder plugins already imported.
@@ -34,74 +36,87 @@ final class Finder extends CMSPlugin
3436 */
3537 protected $ pluginsImported = false ;
3638
39+ /**
40+ * Returns an array of events this subscriber will listen to.
41+ *
42+ * @return array
43+ *
44+ * @since __DEPLOY_VERSION__
45+ */
46+ public static function getSubscribedEvents (): array
47+ {
48+ return [
49+ 'onContentBeforeSave ' => 'onContentBeforeSave ' ,
50+ 'onContentAfterSave ' => 'onContentAfterSave ' ,
51+ 'onContentAfterDelete ' => 'onContentAfterDelete ' ,
52+ 'onContentChangeState ' => 'onContentChangeState ' ,
53+ 'onCategoryChangeState ' => 'onCategoryChangeState ' ,
54+ ];
55+ }
56+
3757 /**
3858 * Smart Search after save content method.
3959 * Content is passed by reference, but after the save, so no changes will be saved.
4060 * Method is called right after the content is saved.
4161 *
42- * @param string $context The context of the content passed to the plugin (added in 1.6)
43- * @param object $article A \Joomla\CMS\Table\Table\ object
44- * @param bool $isNew If the content has just been created
62+ * @param Model\AfterSaveEvent $event The event instance.
4563 *
4664 * @return void
4765 *
4866 * @since 2.5
4967 */
50- public function onContentAfterSave ($ context , $ article , $ isNew ): void
68+ public function onContentAfterSave (Model \ AfterSaveEvent $ event ): void
5169 {
5270 $ this ->importFinderPlugins ();
5371
5472 // Trigger the onFinderAfterSave event.
5573 $ this ->getDispatcher ()->dispatch ('onFinderAfterSave ' , new FinderEvent \AfterSaveEvent ('onFinderAfterSave ' , [
56- 'context ' => $ context ,
57- 'subject ' => $ article ,
58- 'isNew ' => $ isNew ,
74+ 'context ' => $ event -> getContext () ,
75+ 'subject ' => $ event -> getItem () ,
76+ 'isNew ' => $ event -> getIsNew () ,
5977 ]));
6078 }
6179
6280 /**
6381 * Smart Search before save content method.
6482 * Content is passed by reference. Method is called before the content is saved.
6583 *
66- * @param string $context The context of the content passed to the plugin (added in 1.6).
67- * @param object $article A \Joomla\CMS\Table\Table\ object.
68- * @param bool $isNew If the content is just about to be created.
84+ * @param Model\BeforeSaveEvent $event The event instance.
6985 *
7086 * @return void
7187 *
7288 * @since 2.5
7389 */
74- public function onContentBeforeSave ($ context , $ article , $ isNew )
90+ public function onContentBeforeSave (Model \ BeforeSaveEvent $ event )
7591 {
7692 $ this ->importFinderPlugins ();
7793
7894 // Trigger the onFinderBeforeSave event.
7995 $ this ->getDispatcher ()->dispatch ('onFinderBeforeSave ' , new FinderEvent \BeforeSaveEvent ('onFinderBeforeSave ' , [
80- 'context ' => $ context ,
81- 'subject ' => $ article ,
82- 'isNew ' => $ isNew ,
96+ 'context ' => $ event -> getContext () ,
97+ 'subject ' => $ event -> getItem () ,
98+ 'isNew ' => $ event -> getIsNew () ,
8399 ]));
84100 }
85101
86102 /**
87103 * Smart Search after delete content method.
88104 * Content is passed by reference, but after the deletion.
89105 *
90- * @param string $context The context of the content passed to the plugin (added in 1.6).
91- * @param object $article A \Joomla\CMS\Table\Table object.
106+ * @param Model\AfterDeleteEvent $event The event instance.
92107 *
93108 * @return void
94109 *
95110 * @since 2.5
96111 */
97- public function onContentAfterDelete ($ context , $ article ): void
112+ public function onContentAfterDelete (Model \ AfterDeleteEvent $ event ): void
98113 {
99114 $ this ->importFinderPlugins ();
100115
101116 // Trigger the onFinderAfterDelete event.
102117 $ this ->getDispatcher ()->dispatch ('onFinderAfterDelete ' , new FinderEvent \AfterDeleteEvent ('onFinderAfterDelete ' , [
103- 'context ' => $ context ,
104- 'subject ' => $ article ,
118+ 'context ' => $ event -> getContext () ,
119+ 'subject ' => $ event -> getItem () ,
105120 ]));
106121 }
107122
@@ -111,23 +126,21 @@ public function onContentAfterDelete($context, $article): void
111126 * from outside the edit screen. This is fired when the item is published,
112127 * unpublished, archived, or unarchived from the list view.
113128 *
114- * @param string $context The context for the content passed to the plugin.
115- * @param array $pks A list of primary key ids of the content that has changed state.
116- * @param integer $value The value of the state that the content has been changed to.
129+ * @param Model\AfterChangeStateEvent $event The event instance.
117130 *
118131 * @return void
119132 *
120133 * @since 2.5
121134 */
122- public function onContentChangeState ($ context , $ pks , $ value )
135+ public function onContentChangeState (Model \ AfterChangeStateEvent $ event )
123136 {
124137 $ this ->importFinderPlugins ();
125138
126139 // Trigger the onFinderChangeState event.
127140 $ this ->getDispatcher ()->dispatch ('onFinderChangeState ' , new FinderEvent \AfterChangeStateEvent ('onFinderChangeState ' , [
128- 'context ' => $ context ,
129- 'subject ' => $ pks ,
130- 'value ' => $ value ,
141+ 'context ' => $ event -> getContext () ,
142+ 'subject ' => $ event -> getPks () ,
143+ 'value ' => $ event -> getValue () ,
131144 ]));
132145 }
133146
@@ -136,23 +149,21 @@ public function onContentChangeState($context, $pks, $value)
136149 * Method is called when the state of the category to which the
137150 * content item belongs is changed.
138151 *
139- * @param string $extension The extension whose category has been updated.
140- * @param array $pks A list of primary key ids of the content that has changed state.
141- * @param integer $value The value of the state that the content has been changed to.
152+ * @param Model\AfterCategoryChangeStateEvent $event The event instance.
142153 *
143154 * @return void
144155 *
145156 * @since 2.5
146157 */
147- public function onCategoryChangeState ($ extension , $ pks , $ value )
158+ public function onCategoryChangeState (Model \ AfterCategoryChangeStateEvent $ event )
148159 {
149160 $ this ->importFinderPlugins ();
150161
151162 // Trigger the onFinderCategoryChangeState event.
152163 $ this ->getDispatcher ()->dispatch ('onFinderCategoryChangeState ' , new FinderEvent \AfterCategoryChangeStateEvent ('onFinderCategoryChangeState ' , [
153- 'context ' => $ extension ,
154- 'subject ' => $ pks ,
155- 'value ' => $ value ,
164+ 'context ' => $ event -> getExtension () ,
165+ 'subject ' => $ event -> getPks () ,
166+ 'value ' => $ event -> getValue () ,
156167 ]));
157168 }
158169
0 commit comments