* @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\EditorsXtd\Menu\Extension; 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\Event\SubscriberInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Editor menu button * * @since 3.7.0 */ final class Menu extends CMSPlugin implements SubscriberInterface { /** * Returns an array of events this subscriber will listen to. * * @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 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 * * @param string $name The name of the button to add * * @return Button|void The button options as Button object * * @since 3.7.0 * * @deprecated 5.0 Use onEditorButtonsSetup event */ public function onDisplay($name) { $user = $this->getApplication()->getIdentity(); if ( $user->authorise('core.create', 'com_menus') || $user->authorise('core.edit', 'com_menus') ) { $this->loadLanguage(); $link = 'index.php?option=com_menus&view=items&layout=modal&tmpl=component&' . Session::getFormToken() . '=1&editor=' . $name; $button = new Button( $this->_name, [ 'action' => 'modal', 'link' => $link, 'text' => Text::_('PLG_EDITORS-XTD_MENU_BUTTON_MENU'), 'icon' => 'list', 'iconSVG' => '', // This is whole Plugin name, it is needed for keeping backward compatibility 'name' => $this->_type . '_' . $this->_name, ] ); return $button; } } }