Skip to content

Commit

Permalink
Convert the content plugins to service providers (#40561)
Browse files Browse the repository at this point in the history
* Convert the content plugins to service providers

* functions

* namespaces

* doc

* get application from plugin (#29)

* get application from plugin

* Revert pagenavigation

---------

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
  • Loading branch information
laoneo and heelc29 authored May 23, 2023
1 parent 83ef3c2 commit c19e807
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 141 deletions.
5 changes: 3 additions & 2 deletions plugins/content/finder/finder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTENT_FINDER_XML_DESCRIPTION</description>

<namespace path="src">Joomla\Plugin\Content\Finder</namespace>
<files>
<filename plugin="finder">finder.php</filename>
<folder plugin="finder">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_finder.ini</language>
Expand Down
47 changes: 47 additions & 0 deletions plugins/content/finder/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Content.finder
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Content\Finder\Extension\Finder;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Finder(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'finder')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Factory;
namespace Joomla\Plugin\Content\Finder\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;

Expand All @@ -23,7 +22,7 @@
*
* @since 2.5
*/
class PlgContentFinder extends CMSPlugin
final class Finder extends CMSPlugin
{
/**
* Smart Search after save content method.
Expand All @@ -43,7 +42,7 @@ public function onContentAfterSave($context, $article, $isNew): void
PluginHelper::importPlugin('finder');

// Trigger the onFinderAfterSave event.
Factory::getApplication()->triggerEvent('onFinderAfterSave', [$context, $article, $isNew]);
$this->getApplication()->triggerEvent('onFinderAfterSave', [$context, $article, $isNew]);
}

/**
Expand All @@ -63,7 +62,7 @@ public function onContentBeforeSave($context, $article, $isNew)
PluginHelper::importPlugin('finder');

// Trigger the onFinderBeforeSave event.
Factory::getApplication()->triggerEvent('onFinderBeforeSave', [$context, $article, $isNew]);
$this->getApplication()->triggerEvent('onFinderBeforeSave', [$context, $article, $isNew]);
}

/**
Expand All @@ -82,7 +81,7 @@ public function onContentAfterDelete($context, $article): void
PluginHelper::importPlugin('finder');

// Trigger the onFinderAfterDelete event.
Factory::getApplication()->triggerEvent('onFinderAfterDelete', [$context, $article]);
$this->getApplication()->triggerEvent('onFinderAfterDelete', [$context, $article]);
}

/**
Expand All @@ -104,7 +103,7 @@ public function onContentChangeState($context, $pks, $value)
PluginHelper::importPlugin('finder');

// Trigger the onFinderChangeState event.
Factory::getApplication()->triggerEvent('onFinderChangeState', [$context, $pks, $value]);
$this->getApplication()->triggerEvent('onFinderChangeState', [$context, $pks, $value]);
}

/**
Expand All @@ -125,6 +124,6 @@ public function onCategoryChangeState($extension, $pks, $value)
PluginHelper::importPlugin('finder');

// Trigger the onFinderCategoryChangeState event.
Factory::getApplication()->triggerEvent('onFinderCategoryChangeState', [$extension, $pks, $value]);
$this->getApplication()->triggerEvent('onFinderCategoryChangeState', [$extension, $pks, $value]);
}
}
4 changes: 3 additions & 1 deletion plugins/content/joomla/joomla.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTENT_JOOMLA_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\Joomla</namespace>
<files>
<filename plugin="joomla">joomla.php</filename>
<folder plugin="joomla">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_joomla.ini</language>
Expand Down
51 changes: 51 additions & 0 deletions plugins/content/joomla/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Content.joomla
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Content\Joomla\Extension\Joomla;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Joomla(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'joomla')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
$plugin->setUserFactory($container->get(UserFactoryInterface::class));

return $plugin;
}
);
}
};
Loading

0 comments on commit c19e807

Please sign in to comment.