Skip to content
Merged
37 changes: 23 additions & 14 deletions plugins/content/confirmconsent/src/Extension/ConfirmConsent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace Joomla\Plugin\Content\ConfirmConsent\Extension;

use Joomla\CMS\Form\Form;
use Joomla\CMS\Event\Model\PrepareFormEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -22,17 +23,8 @@
*
* @since 3.9.0
*/
final class ConfirmConsent extends CMSPlugin
final class ConfirmConsent extends CMSPlugin implements SubscriberInterface
{
/**
* Load the language file on instantiation.
*
* @var boolean
*
* @since 3.9.0
*/
protected $autoloadLanguage = true;

/**
* The supported form contexts
*
Expand All @@ -45,22 +37,39 @@ final class ConfirmConsent extends CMSPlugin
'com_privacy.request',
];

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onContentPrepareForm' => 'onContentPrepareForm',
];
}

/**
* Add additional fields to the supported forms
*
* @param Form $form The form to be altered.
* @param mixed $data The associated data for the form.
* @param PrepareFormEvent $event The event instance.
*
* @return boolean
*
* @since 3.9.0
*/
public function onContentPrepareForm(Form $form, $data)
public function onContentPrepareForm(PrepareFormEvent $event)
{
$form = $event->getForm();

if ($this->getApplication()->isClient('administrator') || !\in_array($form->getName(), $this->supportedContext)) {
return true;
}

$this->loadLanguage();

// Get the consent box Text & the selected privacyarticle
$consentboxText = (string) $this->params->get(
'consentbox_text',
Expand Down
32 changes: 24 additions & 8 deletions plugins/content/contact/src/Extension/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

namespace Joomla\Plugin\Content\Contact\Extension;

use Joomla\CMS\Event\Content\ContentPrepareEvent;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\Component\Contact\Site\Helper\RouteHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -27,30 +28,45 @@
*
* @since 3.2
*/
final class Contact extends CMSPlugin
final class Contact extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onContentPrepare' => 'onContentPrepare',
];
}

/**
* Plugin that retrieves contact information for contact
*
* @param string $context The context of the content being passed to the plugin.
* @param mixed &$row An object with a "text" property
* @param mixed $params Additional parameters. See {@see PlgContentContent()}.
* @param integer $page Optional page number. Unused. Defaults to zero.
* @param ContentPrepareEvent $event The event instance.
*
* @return void
*/
public function onContentPrepare($context, &$row, $params, $page = 0)
public function onContentPrepare(ContentPrepareEvent $event)
{
$context = $event->getContext();
$row = $event->getItem();
$params = $event->getParams();

$allowed_contexts = ['com_content.category', 'com_content.article', 'com_content.featured'];

if (!\in_array($context, $allowed_contexts)) {
return;
}

// Return if we don't have valid params or don't link the author
if (!($params instanceof Registry) || !$params->get('link_author')) {
if (!$params->get('link_author')) {
return;
}

Expand Down
28 changes: 22 additions & 6 deletions plugins/content/fields/src/Extension/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace Joomla\Plugin\Content\Fields\Extension;

use Joomla\CMS\Event\Content\ContentPrepareEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -23,22 +25,36 @@
*
* @since 3.7.0
*/
final class Fields extends CMSPlugin
final class Fields extends CMSPlugin implements SubscriberInterface
{
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onContentPrepare' => 'onContentPrepare',
];
}

/**
* Plugin that shows a custom field
*
* @param string $context The context of the content being passed to the plugin.
* @param object &$item The item object. Note $article->text is also available
* @param object &$params The article params
* @param int $page The 'page' number
* @param ContentPrepareEvent $event The event instance.
*
* @return void
*
* @since 3.7.0
*/
public function onContentPrepare($context, &$item, &$params, $page = 0)
public function onContentPrepare(ContentPrepareEvent $event)
{
$context = $event->getContext();
$item = $event->getItem();

// If the item has a context, overwrite the existing one
if ($context === 'com_finder.indexer' && !empty($item->context)) {
$context = $item->context;
Expand Down
79 changes: 45 additions & 34 deletions plugins/content/finder/src/Extension/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
namespace Joomla\Plugin\Content\Finder\Extension;

use Joomla\CMS\Event\Finder as FinderEvent;
use Joomla\CMS\Event\Model;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -23,7 +25,7 @@
*
* @since 2.5
*/
final class Finder extends CMSPlugin
final class Finder extends CMSPlugin implements SubscriberInterface
{
/**
* Flag to check whether finder plugins already imported.
Expand All @@ -34,74 +36,87 @@ final class Finder extends CMSPlugin
*/
protected $pluginsImported = false;

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onContentBeforeSave' => 'onContentBeforeSave',
'onContentAfterSave' => 'onContentAfterSave',
'onContentAfterDelete' => 'onContentAfterDelete',
'onContentChangeState' => 'onContentChangeState',
'onCategoryChangeState' => 'onCategoryChangeState',
];
}

/**
* Smart Search after save content method.
* Content is passed by reference, but after the save, so no changes will be saved.
* Method is called right after the content is saved.
*
* @param string $context The context of the content passed to the plugin (added in 1.6)
* @param object $article A \Joomla\CMS\Table\Table\ object
* @param bool $isNew If the content has just been created
* @param Model\AfterSaveEvent $event The event instance.
*
* @return void
*
* @since 2.5
*/
public function onContentAfterSave($context, $article, $isNew): void
public function onContentAfterSave(Model\AfterSaveEvent $event): void
{
$this->importFinderPlugins();

// Trigger the onFinderAfterSave event.
$this->getDispatcher()->dispatch('onFinderAfterSave', new FinderEvent\AfterSaveEvent('onFinderAfterSave', [
'context' => $context,
'subject' => $article,
'isNew' => $isNew,
'context' => $event->getContext(),
'subject' => $event->getItem(),
'isNew' => $event->getIsNew(),
]));
}

/**
* Smart Search before save content method.
* Content is passed by reference. Method is called before the content is saved.
*
* @param string $context The context of the content passed to the plugin (added in 1.6).
* @param object $article A \Joomla\CMS\Table\Table\ object.
* @param bool $isNew If the content is just about to be created.
* @param Model\BeforeSaveEvent $event The event instance.
*
* @return void
*
* @since 2.5
*/
public function onContentBeforeSave($context, $article, $isNew)
public function onContentBeforeSave(Model\BeforeSaveEvent $event)
{
$this->importFinderPlugins();

// Trigger the onFinderBeforeSave event.
$this->getDispatcher()->dispatch('onFinderBeforeSave', new FinderEvent\BeforeSaveEvent('onFinderBeforeSave', [
'context' => $context,
'subject' => $article,
'isNew' => $isNew,
'context' => $event->getContext(),
'subject' => $event->getItem(),
'isNew' => $event->getIsNew(),
]));
}

/**
* Smart Search after delete content method.
* Content is passed by reference, but after the deletion.
*
* @param string $context The context of the content passed to the plugin (added in 1.6).
* @param object $article A \Joomla\CMS\Table\Table object.
* @param Model\AfterDeleteEvent $event The event instance.
*
* @return void
*
* @since 2.5
*/
public function onContentAfterDelete($context, $article): void
public function onContentAfterDelete(Model\AfterDeleteEvent $event): void
{
$this->importFinderPlugins();

// Trigger the onFinderAfterDelete event.
$this->getDispatcher()->dispatch('onFinderAfterDelete', new FinderEvent\AfterDeleteEvent('onFinderAfterDelete', [
'context' => $context,
'subject' => $article,
'context' => $event->getContext(),
'subject' => $event->getItem(),
]));
}

Expand All @@ -111,23 +126,21 @@ public function onContentAfterDelete($context, $article): void
* from outside the edit screen. This is fired when the item is published,
* unpublished, archived, or unarchived from the list view.
*
* @param string $context The context for the content passed to the plugin.
* @param array $pks A list of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
* @param Model\AfterChangeStateEvent $event The event instance.
*
* @return void
*
* @since 2.5
*/
public function onContentChangeState($context, $pks, $value)
public function onContentChangeState(Model\AfterChangeStateEvent $event)
{
$this->importFinderPlugins();

// Trigger the onFinderChangeState event.
$this->getDispatcher()->dispatch('onFinderChangeState', new FinderEvent\AfterChangeStateEvent('onFinderChangeState', [
'context' => $context,
'subject' => $pks,
'value' => $value,
'context' => $event->getContext(),
'subject' => $event->getPks(),
'value' => $event->getValue(),
]));
}

Expand All @@ -136,23 +149,21 @@ public function onContentChangeState($context, $pks, $value)
* Method is called when the state of the category to which the
* content item belongs is changed.
*
* @param string $extension The extension whose category has been updated.
* @param array $pks A list of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
* @param Model\AfterCategoryChangeStateEvent $event The event instance.
*
* @return void
*
* @since 2.5
*/
public function onCategoryChangeState($extension, $pks, $value)
public function onCategoryChangeState(Model\AfterCategoryChangeStateEvent $event)
{
$this->importFinderPlugins();

// Trigger the onFinderCategoryChangeState event.
$this->getDispatcher()->dispatch('onFinderCategoryChangeState', new FinderEvent\AfterCategoryChangeStateEvent('onFinderCategoryChangeState', [
'context' => $extension,
'subject' => $pks,
'value' => $value,
'context' => $event->getExtension(),
'subject' => $event->getPks(),
'value' => $event->getValue(),
]));
}

Expand Down
Loading