From fb3a023e30a09d8185a1a59a3d9c00d61702a53f Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 9 Jun 2026 15:58:08 +0200 Subject: [PATCH 1/5] Implement SubscriberInterface in Weblink plugin --- .../weblink/src/Extension/Weblink.php | 80 +++++++++++-------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php index dc630ba7b7..91ec40530c 100644 --- a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php +++ b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php @@ -14,19 +14,19 @@ \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects -use Joomla\CMS\Application\CMSApplicationInterface; +use Joomla\CMS\Editor\Button\Button; +use Joomla\CMS\Event\Editor\EditorButtonsSetupEvent; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Session\Session; -use Joomla\Database\DatabaseInterface; -use Joomla\Event\DispatcherInterface; +use Joomla\Event\SubscriberInterface; /** * Editor Web Link button * * @since 5.1.0 */ -final class Weblink extends CMSPlugin +final class Weblink extends CMSPlugin implements SubscriberInterface { /** * Load the language file on instantiation. @@ -37,19 +37,39 @@ final class Weblink extends CMSPlugin protected $autoloadLanguage = true; /** - * Constructor + * Returns an array of events this subscriber will listen to. * - * @param DispatcherInterface $dispatcher - * @param array $config - * @param DatabaseInterface $database + * @return array + * + * @since 5.2.0 */ - public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application) + public static function getSubscribedEvents(): array { - parent::__construct($dispatcher, $config); - - $this->setApplication($application); + return ['onEditorButtonsSetup' => 'onEditorButtonsSetup']; } + /** + * @param EditorButtonsSetupEvent $event + * @return void + * + * @since 5.2.0 + */ + public function onEditorButtonsSetup(EditorButtonsSetupEvent $event): void + { + $subject = $event->getButtonsRegistry(); + $disabled = $event->getDisabledButtons(); + + if (\in_array($this->_name, $disabled)) { + return; + } + + $button = $this->onDisplay($event->getEditorId()); + + if ($button) { + $subject->add($button); + } + } + /** * Display the button * @@ -72,27 +92,21 @@ public function onDisplay($name): ?object $link = 'index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&' . Session::getFormToken() . '=1&editor=' . $name; - $button = new \stdClass(); - $button->modal = true; - $button->link = $link; - $button->text = Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK'); - $button->name = $this->_type . '_' . $this->_name; - $button->icon = 'globe'; - // phpcs:disable Generic.Files.LineLength - $button->iconSVG = ' + $button = new Button( + $this->_name, + [ + 'action' => 'modal', + 'link' => $link, + 'text' => Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK'), + 'icon' => 'globe', + 'iconSVG' => ' - '; - // phpcs:enable Generic.Files.LineLength - $button->options = [ - 'height' => '300px', - 'width' => '800px', - 'bodyHeight' => '70', - 'modalWidth' => '80', - ]; - - return $button; - } - - return null; // return null if conditions are not met + ', + // This is whole Plugin name, it is needed for keeping backward compatibility + 'name' => $this->_type . '_' . $this->_name, + ] + ); + return $button; + } } } From ad9cd408c28cc5a1a07ce4a73bbd6c7b52c41e5d Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 9 Jun 2026 16:00:10 +0200 Subject: [PATCH 2/5] Refactor provider.php to use lazy loading for Weblink --- .../editors-xtd/weblink/services/provider.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/plugins/editors-xtd/weblink/services/provider.php b/src/plugins/editors-xtd/weblink/services/provider.php index 4e7a1a40ab..f6c4daf037 100644 --- a/src/plugins/editors-xtd/weblink/services/provider.php +++ b/src/plugins/editors-xtd/weblink/services/provider.php @@ -32,18 +32,16 @@ */ public function register(Container $container) { - $container->set( + $container->set( PluginInterface::class, - function (Container $container) { - $app = Factory::getApplication(); - $dispatcher = $container->get(DispatcherInterface::class); - - return new Weblink( - $dispatcher, - (array) PluginHelper::getPlugin('editors-xtd', 'weblink'), - $app + $container->lazy(Weblink::class, function (Container $container) { + $plugin = new Weblink( + (array) PluginHelper::getPlugin('editors-xtd', 'weblink') ); - } + $plugin->setApplication(Factory::getApplication()); + + return $plugin; + }) ); } }; From 02b941d8f2e0bcfe57f89e463f36bf39f0295e89 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 9 Jun 2026 16:30:01 +0200 Subject: [PATCH 3/5] Remove unused DispatcherInterface import --- src/plugins/editors-xtd/weblink/services/provider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plugins/editors-xtd/weblink/services/provider.php b/src/plugins/editors-xtd/weblink/services/provider.php index f6c4daf037..a09919f2ee 100644 --- a/src/plugins/editors-xtd/weblink/services/provider.php +++ b/src/plugins/editors-xtd/weblink/services/provider.php @@ -17,7 +17,6 @@ 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 { @@ -32,7 +31,7 @@ */ public function register(Container $container) { - $container->set( + $container->set( PluginInterface::class, $container->lazy(Weblink::class, function (Container $container) { $plugin = new Weblink( From 5b7e2013681fe9edbd7b028c796bdbb5e77a6bf8 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 9 Jun 2026 16:30:58 +0200 Subject: [PATCH 4/5] cs --- src/plugins/editors-xtd/weblink/src/Extension/Weblink.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php index 91ec40530c..92be784eed 100644 --- a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php +++ b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php @@ -69,7 +69,7 @@ public function onEditorButtonsSetup(EditorButtonsSetupEvent $event): void $subject->add($button); } } - + /** * Display the button * @@ -106,7 +106,7 @@ public function onDisplay($name): ?object 'name' => $this->_type . '_' . $this->_name, ] ); - return $button; - } + return $button; + } } } From 1e51cbc64741452faca962c45894632960c93ddf Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 9 Jun 2026 16:38:51 +0200 Subject: [PATCH 5/5] cs --- .../weblink/src/Extension/Weblink.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php index 92be784eed..53d1cb9bbd 100644 --- a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php +++ b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php @@ -99,9 +99,21 @@ public function onDisplay($name): ?object 'link' => $link, 'text' => Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK'), 'icon' => 'globe', - 'iconSVG' => ' - - ', + 'iconSVG' => '' . + '' . + '', // This is whole Plugin name, it is needed for keeping backward compatibility 'name' => $this->_type . '_' . $this->_name, ]