ActiveEditor.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Block\Wysiwyg;
  7. use Magento\Framework\View\Element\Template\Context;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Ui\Model;
  10. /**
  11. * ActiveEditor block
  12. *
  13. * @api
  14. * @since 101.1.0
  15. */
  16. class ActiveEditor extends \Magento\Framework\View\Element\Template
  17. {
  18. const DEFAULT_EDITOR_PATH = 'mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter';
  19. /**
  20. * @var ScopeConfigInterface
  21. */
  22. private $scopeConfig;
  23. /**
  24. * @var array
  25. */
  26. private $availableAdapterPaths;
  27. /**
  28. * ActiveEditor constructor.
  29. * @param Context $context
  30. * @param ScopeConfigInterface $scopeConfig
  31. * @param array $availableAdapterPaths
  32. * @param array $data
  33. */
  34. public function __construct(
  35. Context $context,
  36. ScopeConfigInterface $scopeConfig,
  37. $availableAdapterPaths = [],
  38. array $data = []
  39. ) {
  40. parent::__construct($context, $data);
  41. $this->scopeConfig = $scopeConfig;
  42. $this->availableAdapterPaths = $availableAdapterPaths;
  43. }
  44. /**
  45. * Get active wysiwyg adapter path
  46. *
  47. * @return string
  48. * @since 101.1.0
  49. */
  50. public function getWysiwygAdapterPath()
  51. {
  52. $adapterPath = $this->scopeConfig->getValue(Model\Config::WYSIWYG_EDITOR_CONFIG_PATH);
  53. if ($adapterPath !== self::DEFAULT_EDITOR_PATH && !isset($this->availableAdapterPaths[$adapterPath])) {
  54. $adapterPath = self::DEFAULT_EDITOR_PATH;
  55. }
  56. return $this->escapeHtml($adapterPath);
  57. }
  58. }