Convert weblink editor-xtd plugin to service provider structure

This commit is contained in:
Tuan Pham Ngoc 2023-03-16 15:32:37 +07:00
parent 8d928181e9
commit 11a50bf1cc
3 changed files with 70 additions and 11 deletions

View File

@ -0,0 +1,46 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors-xtd.article
*
* @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\EditorsXtd\Weblink\Extension\Weblink;
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)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
return new Weblink(
$dispatcher,
(array) PluginHelper::getPlugin('editors-xtd', 'weblink'),
Factory::getApplication()
);
}
);
}
};

View File

@ -7,28 +7,26 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\EditorsXtd\Weblink\Extension;
defined('_JEXEC') or die;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
use Joomla\Event\DispatcherInterface;
/**
* Editor Web Link button
*
* @since __DEPLOY_VERSION__
*/
class PlgButtonWeblink extends CMSPlugin
final class Weblink extends CMSPlugin
{
/**
* Application object
*
* @var \Joomla\CMS\Application\CMSApplicationInterface
* @since 4.0.0
*/
protected $app;
/**
* Load the language file on instantiation.
*
@ -37,18 +35,32 @@ class PlgButtonWeblink extends CMSPlugin
*/
protected $autoloadLanguage = true;
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application)
{
parent::__construct($dispatcher, $config);
$this->setApplication($application);
}
/**
* Display the button
*
* @param string $name The name of the button to add
*
* @return JObject The button options as JObject
* @return CMSObject The button options as JObject
*
* @since __DEPLOY_VERSION__
*/
public function onDisplay($name)
{
$user = $this->app->getIdentity();
$user = $this->getApplication()->getIdentity();
if ($user->authorise('core.create', 'com_weblinks')
|| $user->authorise('core.edit', 'com_weblinks')

View File

@ -9,6 +9,7 @@
<authorUrl>www.joomla.org</authorUrl>
<version>##VERSION##</version>
<description>PLG_EDITORS-XTD_WEBLINK_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\EditorsXtd\Weblink</namespace>
<files>
##FILES##
</files>