[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/editors/tinymce/src/Field/ -> TinymcebuilderField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Editors.tinymce
   6   *
   7   * @copyright   (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Plugin\Editors\TinyMCE\Field;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Form;
  15  use Joomla\CMS\Form\FormField;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\Plugin\PluginHelper;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Form Field class for the TinyMCE editor.
  25   *
  26   * @package     Joomla.Plugin
  27   * @subpackage  Editors.tinymce
  28   * @since       3.7.0
  29   */
  30  class TinymcebuilderField extends FormField
  31  {
  32      /**
  33       * The form field type.
  34       *
  35       * @var    string
  36       * @since  3.7.0
  37       */
  38      protected $type = 'tinymcebuilder';
  39  
  40      /**
  41       * Name of the layout being used to render the field
  42       *
  43       * @var    string
  44       * @since  3.7.0
  45       */
  46      protected $layout = 'plugins.editors.tinymce.field.tinymcebuilder';
  47  
  48      /**
  49       * The prepared layout data
  50       *
  51       * @var    array
  52       * @since  3.7.0
  53       */
  54      protected $layoutData = array();
  55  
  56      /**
  57       * Method to get the data to be passed to the layout for rendering.
  58       *
  59       * @return  array
  60       *
  61       * @since  3.7.0
  62       */
  63      protected function getLayoutData()
  64      {
  65          if (!empty($this->layoutData)) {
  66              return $this->layoutData;
  67          }
  68  
  69          $data       = parent::getLayoutData();
  70          $paramsAll  = (object) $this->form->getValue('params');
  71          $setsAmount = empty($paramsAll->sets_amount) ? 3 : $paramsAll->sets_amount;
  72  
  73          if (empty($data['value'])) {
  74              $data['value'] = array();
  75          }
  76  
  77          // Get the plugin
  78          require_once JPATH_PLUGINS . '/editors/tinymce/tinymce.php';
  79  
  80          $menus = array(
  81              'edit'   => array('label' => 'Edit'),
  82              'insert' => array('label' => 'Insert'),
  83              'view'   => array('label' => 'View'),
  84              'format' => array('label' => 'Format'),
  85              'table'  => array('label' => 'Table'),
  86              'tools'  => array('label' => 'Tools'),
  87              'help'   => array('label' => 'Help'),
  88          );
  89  
  90          $data['menus']         = $menus;
  91          $data['menubarSource'] = array_keys($menus);
  92          $data['buttons']       = \PlgEditorTinymce::getKnownButtons();
  93          $data['buttonsSource'] = array_keys($data['buttons']);
  94          $data['toolbarPreset'] = \PlgEditorTinymce::getToolbarPreset();
  95          $data['setsAmount']    = $setsAmount;
  96  
  97          // Get array of sets names
  98          for ($i = 0; $i < $setsAmount; $i++) {
  99              $data['setsNames'][$i] = Text::sprintf('PLG_TINY_SET_TITLE', $i);
 100          }
 101  
 102          // Prepare the forms for each set
 103          $setsForms  = array();
 104          $formsource = JPATH_PLUGINS . '/editors/tinymce/forms/setoptions.xml';
 105  
 106          // Preload an old params for B/C
 107          $setParams = new \stdClass();
 108  
 109          if (!empty($paramsAll->html_width) && empty($paramsAll->configuration['setoptions'])) {
 110              $plugin = PluginHelper::getPlugin('editors', 'tinymce');
 111  
 112              Factory::getApplication()->enqueueMessage(Text::sprintf('PLG_TINY_LEGACY_WARNING', '#'), 'warning');
 113  
 114              if (\is_object($plugin) && !empty($plugin->params)) {
 115                  $setParams = (object) json_decode($plugin->params);
 116              }
 117          }
 118  
 119          // Collect already used groups
 120          $groupsInUse = array();
 121  
 122          // Prepare the Set forms, for the set options
 123          foreach (array_keys($data['setsNames']) as $num) {
 124              $formname = 'set.form.' . $num;
 125              $control  = $this->name . '[setoptions][' . $num . ']';
 126  
 127              $setsForms[$num] = Form::getInstance($formname, $formsource, array('control' => $control));
 128  
 129              // Check whether we already have saved values or it first time or even old params
 130              if (empty($this->value['setoptions'][$num])) {
 131                  $formValues = $setParams;
 132  
 133                  /*
 134                   * Predefine group:
 135                   * Set 0: for Administrator, Editor, Super Users (4,7,8)
 136                   * Set 1: for Registered, Manager (2,6), all else are public
 137                   */
 138                  $formValues->access = !$num ? array(4, 7, 8) : ($num === 1 ? array(2, 6) : array());
 139  
 140                  // Assign Public to the new Set, but only when it not in use already
 141                  if (empty($formValues->access) && !\in_array(1, $groupsInUse)) {
 142                      $formValues->access = array(1);
 143                  }
 144              } else {
 145                  $formValues = (object) $this->value['setoptions'][$num];
 146              }
 147  
 148              // Collect already used groups
 149              if (!empty($formValues->access)) {
 150                  $groupsInUse = array_merge($groupsInUse, $formValues->access);
 151              }
 152  
 153              // Bind the values
 154              $setsForms[$num]->bind($formValues);
 155          }
 156  
 157          $data['setsForms'] = $setsForms;
 158  
 159          // Check for TinyMCE language file
 160          $language      = Factory::getLanguage();
 161          $languageFile1 = 'media/vendor/tinymce/langs/' . $language->getTag() . (JDEBUG ? '.js' : '.min.js');
 162          $languageFile2 = 'media/vendor/tinymce/langs/' . substr($language->getTag(), 0, strpos($language->getTag(), '-')) . (JDEBUG ? '.js' : '.min.js');
 163  
 164          $data['languageFile'] = '';
 165  
 166          if (file_exists(JPATH_ROOT . '/' . $languageFile1)) {
 167              $data['languageFile'] = $languageFile1;
 168          } elseif (file_exists(JPATH_ROOT . '/' . $languageFile2)) {
 169              $data['languageFile'] = $languageFile2;
 170          }
 171  
 172          $this->layoutData = $data;
 173  
 174          return $data;
 175      }
 176  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer