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

[5.3] [Events] Use event classes for System plugins #43637

Open
wants to merge 19 commits into
base: 5.3-dev
Choose a base branch
from
Prev Previous commit
Next Next commit
system highlight
  • Loading branch information
Fedik committed Jun 8, 2024
commit 8c8cb12f145ca4b863951492bd76b52ca988fe5b
2 changes: 2 additions & 0 deletions plugins/system/accessibility/src/Extension/Accessibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static function getSubscribedEvents(): array
/**
* Add the javascript for the accessibility menu
*
* @param BeforeCompileHeadEvent $event The event object
*
* @return void
*
* @since 4.0.0
Expand Down
1 change: 0 additions & 1 deletion plugins/system/fields/src/Extension/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static function getSubscribedEvents(): array
'onContentAfterTitle' => 'onContentAfterTitle',
'onContentBeforeDisplay' => 'onContentBeforeDisplay',
'onContentAfterDisplay' => 'onContentAfterDisplay',

];
}

Expand Down
1 change: 0 additions & 1 deletion plugins/system/highlight/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function (Container $container) {
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'highlight')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
Expand Down
39 changes: 30 additions & 9 deletions plugins/system/highlight/src/Extension/Highlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
namespace Joomla\Plugin\System\Highlight\Extension;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\BeforeCompileHeadEvent;
use Joomla\CMS\Event\Finder\ResultEvent;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Finder\Administrator\Indexer\Result;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -24,28 +26,45 @@
*
* @since 2.5
*/
final class Highlight extends CMSPlugin
final class Highlight 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 [
'onAfterDispatch' => 'onAfterDispatch',
'onFinderResult' => 'onFinderResult',
];
}

/**
* Method to catch the onAfterDispatch event.
*
* This is where we setup the click-through content highlighting for.
* The highlighting is done with JavaScript so we just
* need to check a few parameters and the JHtml behavior will do the rest.
*
* @param BeforeCompileHeadEvent $event The event object
*
* @return void
*
* @since 2.5
*/
public function onAfterDispatch()
public function onAfterDispatch(BeforeCompileHeadEvent $event): void
{
// Check that we are in the site application.
if (!$this->getApplication()->isClient('site')) {
if (!$event->getApplication()->isClient('site')) {
return;
}

// Set the variables.
$input = $this->getApplication()->getInput();
$input = $event->getApplication();
$extension = $input->get('option', '', 'cmd');

// Check if the highlighter is enabled.
Expand Down Expand Up @@ -77,7 +96,7 @@ public function onAfterDispatch()
}

/** @var \Joomla\CMS\Document\HtmlDocument $doc */
$doc = $this->getApplication()->getDocument();
$doc = $event->getDocument();

// Activate the highlighter.
if (!empty($cleanTerms)) {
Expand All @@ -100,21 +119,23 @@ public function onAfterDispatch()
/**
* Method to catch the onFinderResult event.
*
* @param Result $item The search result
* @param object $query The search query of this result
* @param ResultEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onFinderResult($item, $query)
public function onFinderResult(ResultEvent $event): void
{
static $params;

if (\is_null($params)) {
$params = ComponentHelper::getParams('com_finder');
}

$item = $event->getItem();
$query = $event->getQuery();

// Get the route with highlighting information.
if (
!empty($query->highlight)
Expand Down