class TinyMCEConfig extends HTMLEditorConfig implements i18nEntityProvider (View source)

Default configuration for HtmlEditor specific to tinymce

Traits

Provides extensions to this object to integrate it with standard config API methods.

A class that can be instantiated or replaced via DI

Config options

default_config string

Name of default config. This will be ignored if $current is assigned a value.

from  HTMLEditorConfig
user_themes array

List of themes defined for the frontend

from  HTMLEditorConfig
tinymce_lang array
base_dir string

Location of module relative to BASE_DIR. This must contain the following dirs

  • plugins
  • themes
  • skins
editor_css array

Extra editor.css file paths.

image_size_presets array[]

List of image size preset that will appear when you select an image. Each preset can have the following:

  • name to store an internal name for the preset (required)
  • i18n to store a translation key (e.g.: SilverStripe\Forms\HTMLEditor\TinyMCEConfig.BESTFIT)
  • text that will appear in the button (should be the default English translation)
  • width which will define the horizontal size of the preset. If not provided, the preset will match the original size of the image.

Properties

protected static HTMLEditorConfig[] $configs

Array of registered configurations

from  HTMLEditorConfig
protected static string $current

Identifier key of current config. This will match an array key in $configs.

from  HTMLEditorConfig
protected static array $current_themes

List of the current themes set for this config

from  HTMLEditorConfig
protected string[]|null $contentCSS

List of content css files to use for this instance, or null to default to editor_css config.

protected array $settings

TinyMCE JS settings

protected array $plugins

Holder list of enabled plugins

protected string $theme

Theme name

protected array $buttons

Holder list of buttons, organised by line. This array is 1-based indexed array

Methods

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
stat(string $name) deprecated

Get inherited config value

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
$this
set_stat(string $name, mixed $value) deprecated

Update the config value for a given property

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public static 
get(string $identifier = null)

Get the HTMLEditorConfig object for the given identifier. This is a correct way to get an HTMLEditorConfig instance - do not call 'new'

public static 
set_config(string $identifier, HTMLEditorConfig $config = null)

Assign a new config, or clear existing, for the given identifier

public static 
array
getThemes()

Gets the current themes, if it is not set this will fallback to config

public static 
setThemes(array $themes)

Sets the current theme

public static 
set_active_identifier(string $identifier)

Set the currently active configuration object. Note that the existing active config will not be renamed to the new identifier.

public static 
string
get_active_identifier()

Get the currently active configuration identifier. Will fall back to default_config if unassigned.

public static 
get_active()

Get the currently active configuration object

public static 
set_active(HTMLEditorConfig $config)

Assigns the currently active config an explicit instance

public static 
array
get_available_configs_map()

Get the available configurations as a map of friendly_name to configuration name.

public
mixed
getOption(string $key)

Get the current value of an option

public
$this
setOption(string $key, mixed $value)

Set the value of one option

public
$this
setOptions(array $options)

Set multiple options. This does not merge recursively, but only at the top level.

public
array
getAttributes()

Associative array of data-attributes to apply to the underlying text-area

public
init()

Initialise the editor on the client side

public
array
getConfigSchemaData()

Provide additional schema data for the field this object configures

public
string
getTheme()

Get the theme

public
$this
setTheme(string $theme)

Set the theme name

protected
array
getSettings()

Get all settings

public
$this
enablePlugins(string|array $plugin)

Enable one or several plugins. Will maintain unique list if already enabled plugin is re-passed. If passed in as a map of plugin-name to path, the plugin will be loaded by tinymce.PluginManager.load() instead of through tinyMCE.init().

public
$this
disablePlugins(string|array $plugin)

Enable one or several plugins. Will properly handle being passed a plugin that is already disabled

public
array
getPlugins()

Gets the list of all enabled plugins as an associative array.

public
array
getInternalPlugins()

Get list of plugins without custom locations, which is the set of plugins which can be loaded via the standard plugin path, and could potentially be minified

public
array
getButtons()

Get all button rows, skipping empty rows

public
$this
setButtonsForLine(int $line, $buttons)

Totally re-set the buttons on a given line

public
$this
addButtonsToLine(int $line, string $buttons)

Add buttons to the end of a line

protected
bool
modifyButtons(string $name, int $offset, int $del = 0, mixed $add = null)

Internal function for adding and removing buttons related to another button

public
bool
insertButtonsBefore(string $before, string $buttons)

Insert buttons before the first occurrence of another button

public
bool
insertButtonsAfter(string $after, string $buttons)

Insert buttons after the first occurrence of another button

public
removeButtons($buttons)

Remove the first occurrence of buttons

protected
array
getConfig()

Generate the JavaScript that will set TinyMCE's configuration:

  • Parse all configurations into JSON objects to be used in JavaScript
  • Includes TinyMCE and configurations using the Requirements system

protected
array
getEditorCSS()

Get location of all editor.css files.

public
string[]
getContentCSS()

Get list of resource paths to css files.

public
$this
setContentCSS(string[] $css)

Set explicit set of CSS resources to use for content_css option.

public
string
getScriptURL()

Generate gzipped TinyMCE configuration including plugins and languages.

public static 
string
get_tinymce_lang()

Get the current tinyMCE language

public
string
getTinyMCEResourcePath()

Returns the full filesystem path to TinyMCE resources (which could be different from the original tinymce location in the module).

public
string
getTinyMCEResourceURL()

Get front-end url to tinymce resources

public
getTinyMCEResource()

Get resource root for TinyMCE, either as a string or ModuleResource instance Path will be relative to BASE_PATH if string.

public
getTinyMCEPath() deprecated

No description

protected
getAdminModule() deprecated

No description

public
setFolderName(string $folderName)

Sets the upload folder name used by the insert media dialog

public
array
provideI18nEntities()

Returns the list of provided translations for this object.

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed stat(string $name) deprecated

deprecated 5.0 Use ->config()->get() instead

Get inherited config value

Parameters

string $name

Return Value

mixed

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

$this set_stat(string $name, mixed $value) deprecated

deprecated 5.0 Use ->config()->set() instead

Update the config value for a given property

Parameters

string $name
mixed $value

Return Value

$this

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

static HTMLEditorConfig get(string $identifier = null)

Get the HTMLEditorConfig object for the given identifier. This is a correct way to get an HTMLEditorConfig instance - do not call 'new'

Parameters

string $identifier

The identifier for the config set. If omitted, the active config is returned.

Return Value

HTMLEditorConfig

The configuration object. This will be created if it does not yet exist for that identifier

static HTMLEditorConfig set_config(string $identifier, HTMLEditorConfig $config = null)

Assign a new config, or clear existing, for the given identifier

Parameters

string $identifier

A specific identifier

HTMLEditorConfig $config

Config to set, or null to clear

Return Value

HTMLEditorConfig

The assigned config

static array getThemes()

Gets the current themes, if it is not set this will fallback to config

Return Value

array

static setThemes(array $themes)

Sets the current theme

Parameters

array $themes

static set_active_identifier(string $identifier)

Set the currently active configuration object. Note that the existing active config will not be renamed to the new identifier.

Parameters

string $identifier

The identifier for the config set

static string get_active_identifier()

Get the currently active configuration identifier. Will fall back to default_config if unassigned.

Return Value

string

The active configuration identifier

static HTMLEditorConfig get_active()

Get the currently active configuration object

Return Value

HTMLEditorConfig

The active configuration object

static HTMLEditorConfig set_active(HTMLEditorConfig $config)

Assigns the currently active config an explicit instance

Parameters

HTMLEditorConfig $config

Return Value

HTMLEditorConfig

The given config

static array get_available_configs_map()

Get the available configurations as a map of friendly_name to configuration name.

Return Value

array

mixed getOption(string $key)

Get the current value of an option

Parameters

string $key

The key of the option to get

Return Value

mixed

The value of the specified option

$this setOption(string $key, mixed $value)

Set the value of one option

Parameters

string $key

The key of the option to set

mixed $value

The value of the option to set

Return Value

$this

$this setOptions(array $options)

Set multiple options. This does not merge recursively, but only at the top level.

Parameters

array $options

The options to set, as keys and values of the array

Return Value

$this

array getAttributes()

Associative array of data-attributes to apply to the underlying text-area

Return Value

array

init()

Initialise the editor on the client side

array getConfigSchemaData()

Provide additional schema data for the field this object configures

Return Value

array

string getTheme()

Get the theme

Return Value

string

$this setTheme(string $theme)

Set the theme name

Parameters

string $theme

Return Value

$this

protected array getSettings()

Get all settings

Return Value

array

$this enablePlugins(string|array $plugin)

Enable one or several plugins. Will maintain unique list if already enabled plugin is re-passed. If passed in as a map of plugin-name to path, the plugin will be loaded by tinymce.PluginManager.load() instead of through tinyMCE.init().

Keep in mind that these externals plugins require a dash-prefix in their name.

Parameters

string|array $plugin

a string, or several strings, or a single array of strings - The plugins to enable

Return Value

$this

See also

http://wiki.moxiecode.com/index.php/TinyMCE:API/tinymce.PluginManager/load If passing in a non-associative array, the plugin name should be located in the standard tinymce plugins folder. If passing in an associative array, the key of each item should be the plugin name. The value of each item is one of: - null - Will be treated as a standard plugin in the standard location - relative path - Will be treated as a relative url - absolute url - Some url to an external plugin - An instance of ModuleResource object containing the plugin

$this disablePlugins(string|array $plugin)

Enable one or several plugins. Will properly handle being passed a plugin that is already disabled

Parameters

string|array $plugin

a string, or several strings, or a single array of strings - The plugins to enable

Return Value

$this

array getPlugins()

Gets the list of all enabled plugins as an associative array.

Array keys are the plugin names, and values are potentially the plugin location, or ModuleResource object

Return Value

array

array getInternalPlugins()

Get list of plugins without custom locations, which is the set of plugins which can be loaded via the standard plugin path, and could potentially be minified

Return Value

array

array getButtons()

Get all button rows, skipping empty rows

Return Value

array

$this setButtonsForLine(int $line, $buttons)

Totally re-set the buttons on a given line

Parameters

int $line

The line number to redefine, from 1 to 3

$buttons

Return Value

$this

$this addButtonsToLine(int $line, string $buttons)

Add buttons to the end of a line

Parameters

int $line

The line number to redefine, from 1 to 3

string $buttons

A string or several strings, or a single array of strings. The button names to add to this line

Return Value

$this

protected bool modifyButtons(string $name, int $offset, int $del = 0, mixed $add = null)

Internal function for adding and removing buttons related to another button

Parameters

string $name

The name of the button to modify

int $offset

The offset relative to that button to perform an array_splice at. 0 for before $name, 1 for after.

int $del

The number of buttons to remove at the position given by index(string) + offset

mixed $add

An array or single item to insert at the position given by index(string) + offset, or null for no insertion

Return Value

bool

True if $name matched a button, false otherwise

bool insertButtonsBefore(string $before, string $buttons)

Insert buttons before the first occurrence of another button

Parameters

string $before

the name of the button to insert other buttons before

string $buttons

a string, or several strings, or a single array of strings. The button names to insert before that button

Return Value

bool

True if insertion occurred, false if it did not (because the given button name was not found)

bool insertButtonsAfter(string $after, string $buttons)

Insert buttons after the first occurrence of another button

Parameters

string $after

the name of the button to insert other buttons before

string $buttons

a string, or several strings, or a single array of strings. The button names to insert after that button

Return Value

bool

True if insertion occurred, false if it did not (because the given button name was not found)

removeButtons($buttons)

Remove the first occurrence of buttons

Parameters

$buttons

protected array getConfig()

Generate the JavaScript that will set TinyMCE's configuration:

  • Parse all configurations into JSON objects to be used in JavaScript
  • Includes TinyMCE and configurations using the Requirements system

Return Value

array

protected array getEditorCSS()

Get location of all editor.css files.

All resource specifiers are resolved to urls.

Return Value

array

string[] getContentCSS()

Get list of resource paths to css files.

Will default to editor_css config, as well as any themed editor.css files. Use setContentCSS() to override.

Return Value

string[]

$this setContentCSS(string[] $css)

Set explicit set of CSS resources to use for content_css option.

Note: If merging with default paths, you should call getContentCSS() and merge prior to assignment.

Parameters

string[] $css

Array of resource paths. Supports module prefix, e.g. silverstripe/admin:client/dist/styles/editor.css

Return Value

$this

string getScriptURL()

Generate gzipped TinyMCE configuration including plugins and languages.

This ends up "pre-loading" TinyMCE bundled with the required plugins so that multiple HTTP requests on the client don't need to be made.

Return Value

string

Exceptions

Exception

static string get_tinymce_lang()

Get the current tinyMCE language

Return Value

string Language

string getTinyMCEResourcePath()

Returns the full filesystem path to TinyMCE resources (which could be different from the original tinymce location in the module).

Path will be absolute.

Return Value

string

Exceptions

Exception

string getTinyMCEResourceURL()

Get front-end url to tinymce resources

Return Value

string

Exceptions

Exception

ModuleResource|string getTinyMCEResource()

Get resource root for TinyMCE, either as a string or ModuleResource instance Path will be relative to BASE_PATH if string.

Return Value

ModuleResource|string

Exceptions

Exception

getTinyMCEPath() deprecated

deprecated 4.0.1 Use getTinyMCEResourcePath() instead

No description

protected Module getAdminModule() deprecated

deprecated 4.0.1 Set base_dir or editor_css config instead

No description

Return Value

Module

TinyMCEConfig setFolderName(string $folderName)

Sets the upload folder name used by the insert media dialog

Parameters

string $folderName

Return Value

TinyMCEConfig

array provideI18nEntities()

Returns the list of provided translations for this object.

Note: Pluralised forms are always returned in array format.

Example usage:

class MyTestClass implements i18nEntityProvider
{
  public function provideI18nEntities()
  {
    $entities = [];
    foreach($this->config()->get('my_static_array') as $key => $value) {
      $entities["MyTestClass.my_static_array_{$key}"] = $value;
    }
    $entities["MyTestClass.PLURALS"] = [
      'one' => 'A test class',
      'other' => '{count} test classes',
    ]
    return $entities;
  }
}

Example usage in DataObject->provideI18nEntities().

You can ask textcollector to add the provided entity to a different module. Simply wrap the returned value for any item in an array with the format: [ 'default' => $defaultValue, 'module' => $module ]

class MyTestClass implements i18nEntityProvider
{
  public function provideI18nEntities()
  {
    $entities = [
      'MyOtherModuleClass.MYENTITY' => [
        'default' => $value,
        'module' => 'myothermodule',
      ]
    ];
  }
  return $entities;
}

Return Value

array

Map of keys to default values, which are strings in the default case, and array-form for pluralisations.