Skip to content

Instantly share code, notes, and snippets.

@FredericMartinez
Created March 18, 2021 10:15
Show Gist options
  • Select an option

  • Save FredericMartinez/1d669682fd6ca607f3528d538f6a8ec2 to your computer and use it in GitHub Desktop.

Select an option

Save FredericMartinez/1d669682fd6ca607f3528d538f6a8ec2 to your computer and use it in GitHub Desktop.

Revisions

  1. FredericMartinez created this gist Mar 18, 2021.
    44 changes: 44 additions & 0 deletions TinyMCEPlugin
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Ui\Component\Wysiwyg\ConfigInterface">
    <plugin name="mynamespace_tinymce_settings"
    type="Namespace\Backend\Plugins\TinyMCEPlugin"
    sortOrder="10"/>
    </type>
    </config>


    class TinyMCEPlugin
    {
    protected $activeEditor;
    public function __construct(\Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor)
    {
    $this->activeEditor = $activeEditor;
    }
    /**
    * Return WYSIWYG configuration
    *
    * @param \Magento\Ui\Component\Wysiwyg\ConfigInterface $configInterface
    * @param \Magento\Framework\DataObject $result
    *
    * @return \Magento\Framework\DataObject
    */
    public function afterGetConfig(
    ConfigInterface $configInterface,
    DataObject $result
    ) {
    // Get current wysiwyg adapter's path
    $editor = $this->activeEditor->getWysiwygAdapterPath();
    // Is the current wysiwyg tinymce v4?
    if (strpos($editor, 'tinymce4Adapter')) {
    $settings = $result->getData('settings');
    if (!is_array($settings)) {
    $settings = [];
    }
    // configure tinymce settings
    $settings['forced_root_block'] = false;
    $result->setData('settings', $settings);
    }
    return $result;
    }
    }