PHPackages                             violet88/silverstripe-tinymce-premium - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. violet88/silverstripe-tinymce-premium

ActiveSilverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

violet88/silverstripe-tinymce-premium
=====================================

A SilverStripe module for integrating the TinyMCE premium plugins in SilverStripe, including adding JavaScript functions as config options.

1.1.1(2y ago)06BSD-3-ClausePHPPHP &gt;=7.4|^8.0

Since Nov 2Pushed 2y agoCompare

[ Source](https://github.com/Violet88github/silverstripe-tinymce-premium)[ Packagist](https://packagist.org/packages/violet88/silverstripe-tinymce-premium)[ RSS](/packages/violet88-silverstripe-tinymce-premium/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

SilverStripe TinyMCE Premium Module
===================================

[](#silverstripe-tinymce-premium-module)

This module provides a way to use your own [TinyMCE Cloud](https://tiny.cloud) API key with SilverStripe TinyMCE fields including the use of using JavaScript as config values.

Requirements
------------

[](#requirements)

- SilverStripe 4.0+
- PHP &gt;= 7.4, &gt;= 8.0
- [TinyMCE Cloud](https://tiny.cloud) API key
- [TinyMCE Premium](https://www.tiny.cloud/pricing/) subscription

Installation
------------

[](#installation)

Install the module using composer.

```
composer require violet88/silverstripe-tinymce-premium
```

Configuration
-------------

[](#configuration)

### TinyMCE

[](#tinymce)

The module requires a TinyMCE Cloud API key to be configured. Make sure to [approve your domains](https://www.tiny.cloud/my-account/domains/) before using the API key. Your API key can be found in the [TinyMCE Cloud dashboard](https://www.tiny.cloud/my-account/dashboard/).

### SilverStripe

[](#silverstripe)

#### Configuration File

[](#configuration-file)

Your cloud API key can be configured in the `tinymce.yml` file.

```
---
name: tinymce-premium
---

Violet88\TinyMCE\TinyMCEPremiumHandler:
    api_key: # Your TinyMCE Cloud API key
```

Additionally, you can configure the TinyMCE Premium plugin options in the `tinymce.yml` file. Don't do this if you don't know what you're doing, the default options are configured to work with SilverStripe 4.

```
Violet88\TinyMCE\TinyMCEPremiumHandler:
    tinymce_version: 4                      # TinyMCE version
    tinymce_cdn: "https://cdn.tiny.cloud/1" # TinyMCE CDN
```

#### Environment Variables

[](#environment-variables)

Additionally, you can configure all of the above using environment variables. This is useful if you want to use the same configuration across multiple environments. The environment variables are prefixed with `TINYMCE_PREMIUM_` and are all uppercase. The `api_key` environment variable is required.

```
TINYMCE_PREMIUM_API_KEY="your-api-key"
TINYMCE_PREMIUM_TINYMCE_VERSION="4"
TINYMCE_PREMIUM_TINYMCE_CDN="https://cdn.tiny.cloud/1"
```

> Environment variables are always prioritized over the configuration file.

Usage
-----

[](#usage)

The module can be used in the `_config.php` file to enable TinyMCE premium plugins and set JavaScript config values.

### Enabling premium plugins

[](#enabling-premium-plugins)

Enabling premium plugins is as easy as enabling any other plugin. The following example enables the `tinymcespellchecker`, `advcode` and `mentions` plugins.

```
$editorConfig = HTMLEditorConfig::get('cms');

if ($editorConfig instanceof TinyMCEConfig) {
    $handler = TinyMCEPremiumHandler::create();

    $editorConfig->enablePlugins([
        'tinymcespellchecker' => $handler->getPluginUrl('tinymcespellchecker'),
        'advcode' => $handler->getPluginUrl('advcode'),
        'mentions' => $handler->getPluginUrl('mentions')
    ]);
}
```

### Setting JavaScript config values

[](#setting-javascript-config-values)

Most of the premium plugins allow you to set callbacks and other JavaScript config values. Since this is not natively supported in the built in PHP based SilverStripe TinyMCE config manager, this module provides a way to set JavaScript config values using the `setJsConfig` method. The following example sets the `mentions` plugin config value `mentions_fetch` to a demo callback.

```
$editorConfig = HTMLEditorConfig::get('cms');

if ($editorConfig instanceof TinyMCEConfig) {
    $handler = TinyMCEPremiumHandler::create();

    $editorConfig->enablePlugins([
        'mentions' => $handler->getPluginUrl('mentions')
    ]);

    $handler->setJsOptions([
        'mentions_fetch' =>
