- md5
- c487e8fd0c81134854d0c2227088018b
- sha1
- d220bd21c07c2855753558e37c8b4f9f996580bf
- sha256
- 0b46e68040f7fc6dce25b5b8f14ba58d60fc1f099d56ee2bd09df1f7f09db7da
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors.tinymce
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Editors\TinyMCE\PluginTraits;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\Event\Event;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Resolves the XTD Buttons for the current TinyMCE editor.
*
* @since 4.1.0
*/
trait XTDButtons
{
/**
* Get the XTD buttons and render them inside tinyMCE
*
* @param string $name the id of the editor field
* @param string $excluded the buttons that should be hidden
*
* @return array|void
*
* @since 4.1.0
*/
private function tinyButtons($name, $excluded)
{
// Get the available buttons
$buttonsEvent = new Event(
'getButtons',
[
'editor' => $name,
'buttons' => $excluded,
]
);
$buttonsResult = $this->getDispatcher()->dispatch('getButtons', $buttonsEvent);
$buttons = $buttonsResult['result'];
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->getApplication()->getDocument()->getWebAssetManager();
if (is_array($buttons) || (is_bool($buttons) && $buttons)) {
Text::script('PLG_TINY_CORE_BUTTONS');
// Init the arrays for the buttons
$btnsNames = [];
// Build the script
foreach ($buttons as $button) {
$title = $button->get('title') ?: $button->get('text', '');
$icon = $button->get('icon');
$link = $button->get('link');
$action = $button->get('action', '');
$options = (array) $button->get('options');
$btnAsset = 'editor-button.' . $button->getButtonName();
// Enable the button assets if any
if ($wa->assetExists('style', $btnAsset)) {
$wa->useStyle($btnAsset);
}
if ($wa->assetExists('script', $btnAsset)) {
$wa->useScript($btnAsset);
}
// Correct the link
if ($link && $link[0] !== '#') {
$link = str_contains($link, '&') ? htmlspecialchars_decode($link) : $link;
$link = Uri::base(true) . '/' . $link;
$options['src'] = $options['src'] ?? $link;
}
// Set action to "modal" for legacy buttons, when possible
$legacyModal = $button->get('modal') && !empty($options['confirmCallback']);
if (!$action && $button->get('modal') && !$legacyModal) {
$action = 'modal';
// Backward compatibility check, for older options
if (!empty($options['modalWidth'])) {
$options['width'] = $options['modalWidth'] . 'vw';
}
if (!empty($options['bodyHeight'])) {
$options['height'] = $options['bodyHeight'] . 'vh';
}
}
// Prepare default values for modal
if ($action === 'modal') {
$this->getApplication()->getDocument()
->getWebAssetManager()->useScript('joomla.dialog');
$options['popupType'] = $options['popupType'] ?? 'iframe';
$options['textHeader'] = $options['textHeader'] ?? $title;
$options['iconHeader'] = $options['iconHeader'] ?? 'icon-' . $icon;
}
$coreButton = [];
$coreButton['name'] = $title;
$coreButton['icon'] = $icon;
$coreButton['click'] = $button->get('onclick');
$coreButton['iconSVG'] = $button->get('iconSVG');
$coreButton['action'] = $action;
$coreButton['options'] = $options;
if ($legacyModal) {
$coreButton['bsModal'] = true;
$coreButton['id'] = $name . '_' . $button->name;
$button->id = $name . '_' . $button->name . '_modal';
echo LayoutHelper::render('joomla.editors.buttons.modal', $button);
}
// The array with the toolbar buttons
$btnsNames[] = $coreButton;
}
sort($btnsNames);
return ['names' => $btnsNames];
}
}
}
No other release has this exact content. See every version of this file.