diff --git a/src/plugins/editors-xtd/weblink/services/provider.php b/src/plugins/editors-xtd/weblink/services/provider.php index 4e7a1a40ab..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 { @@ -34,16 +33,14 @@ public function register(Container $container) { $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; + }) ); } }; diff --git a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php index dc630ba7b7..53d1cb9bbd 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,17 +37,37 @@ 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 static function getSubscribedEvents(): array + { + return ['onEditorButtonsSetup' => 'onEditorButtonsSetup']; + } + + /** + * @param EditorButtonsSetupEvent $event + * @return void + * + * @since 5.2.0 */ - public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application) + public function onEditorButtonsSetup(EditorButtonsSetupEvent $event): void { - parent::__construct($dispatcher, $config); + $subject = $event->getButtonsRegistry(); + $disabled = $event->getDisabledButtons(); - $this->setApplication($application); + if (\in_array($this->_name, $disabled)) { + return; + } + + $button = $this->onDisplay($event->getEditorId()); + + if ($button) { + $subject->add($button); + } } /** @@ -72,27 +92,33 @@ 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 = ' - - '; - // phpcs:enable Generic.Files.LineLength - $button->options = [ - 'height' => '300px', - 'width' => '800px', - 'bodyHeight' => '70', - 'modalWidth' => '80', - ]; - + $button = new Button( + $this->_name, + [ + 'action' => 'modal', + 'link' => $link, + 'text' => Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK'), + 'icon' => 'globe', + 'iconSVG' => '' . + '' . + '', + // This is whole Plugin name, it is needed for keeping backward compatibility + 'name' => $this->_type . '_' . $this->_name, + ] + ); return $button; } - - return null; // return null if conditions are not met } }