abstract class HTMLEditorConfig (View source)

A generic API for WYSIWYG editor configuration, to allow various parameters to be configured on a site or section basis

There can be multiple HTMLEditorConfig's, which should always be created / accessed using HTMLEditorConfig::get. You can then set the currently active config using set_active. The order of precedence for which config is used is (lowest to highest):

  • default_config config setting
  • Active config assigned
  • Config name assigned to HTMLEditorField
  • Config instance assigned to HTMLEditorField

Typically global config changes should set the active config.

The default config class can be changed via dependency injection to replace HTMLEditorConfig.

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.

default_config_definitions array

Associative array of predefined HTMLEditorConfig definitions that can be accessed with the get() method.

default_element_rules

Default set of rules to define which elements and attributes are allowed, and how to treat them.

user_themes array

List of themes defined for the frontend

fixed_row_height int

The height for the editable portion of editor in number of rows.

Properties

protected static HTMLEditorConfig[] $configs

Array of registered configurations

protected static string $current

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

protected static array $current_themes

List of the current themes set for this config

protected static string $configType

A string used to identify this config class in the CMS JavaScript.

protected static string $schemaComponent

The name of the client-side component to inject for fields using this config.

Methods

public static 
config()

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

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

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 
HTMLEditorConfig|null
set_config(string $identifier, HTMLEditorConfig|null $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 
void
setThemes(array $themes)

Sets the current theme

public static 
void
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
setOption(string $key, mixed $value)

Set the value of one option

public
array
getOptions()

Get the options for this config

public
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
void
init()

Initialise the editor on the client side

public
getElementRuleSet()

Get the element rules for server-side sanitisation.

public
setElementRuleSet(HTMLEditorRuleSet $ruleset)

Set the rules for allowed elements and attributes from a HTMLEditorRuleSet.

public
setElementRulesFromArray(array $rulesArray)

Set the rules for allowed elements and attributes from an associative array.

public
string
getSchemaComponent()

Get the name of the client-side component to inject for fields using this config

public
array
getConfigSchemaData()

Provide additional schema data for the field this object configures

public
int|null
getRows()

Get the number of rows this config will use in its editable area.

public
setRows(int $numRows)

Set the number of rows this config will use in its editable area.

protected
string
getConfigType()

Get the string used to identify this config class in the CMS JavaScript.

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 uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

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'

The config instance will be created if one does not yet exist for that identifier.

Parameters

string $identifier

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

Return Value

HTMLEditorConfig

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

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

Parameters

string $identifier

A specific identifier

HTMLEditorConfig|null $config

Config to set, or null to clear

Return Value

HTMLEditorConfig|null

The assigned config or null if cleared

static array getThemes()

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

Return Value

array

static void setThemes(array $themes)

Sets the current theme

Parameters

array $themes

Return Value

void

static void 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

Return Value

void

static string get_active_identifier()

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

Return Value

string

static HTMLEditorConfig get_active()

Get the currently active configuration object

Return Value

HTMLEditorConfig

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

abstract 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

abstract HTMLEditorConfig 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

HTMLEditorConfig

abstract array getOptions()

Get the options for this config

Return Value

array

abstract HTMLEditorConfig 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

HTMLEditorConfig

array getAttributes()

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

Return Value

array

abstract void init()

Initialise the editor on the client side

Return Value

void

abstract HTMLEditorRuleSet getElementRuleSet()

Get the element rules for server-side sanitisation.

Changes made to this ruleset may not affect the config. If you alter it, make sure you pass it into a call to setElementRuleSet().

Return Value

HTMLEditorRuleSet

abstract HTMLEditorConfig setElementRuleSet(HTMLEditorRuleSet $ruleset)

Set the rules for allowed elements and attributes from a HTMLEditorRuleSet.

This will override any previously defined allowed element or attribute rules.

Parameters

HTMLEditorRuleSet $ruleset

Return Value

HTMLEditorConfig

HTMLEditorConfig setElementRulesFromArray(array $rulesArray)

Set the rules for allowed elements and attributes from an associative array.

This will override any previously defined allowed element or attribute rules.

Parameters

array $rulesArray

Return Value

HTMLEditorConfig

string getSchemaComponent()

Get the name of the client-side component to inject for fields using this config

Return Value

string

array getConfigSchemaData()

Provide additional schema data for the field this object configures

Return Value

array

int|null getRows()

Get the number of rows this config will use in its editable area.

Return Value

int|null

HTMLEditorConfig setRows(int $numRows)

Set the number of rows this config will use in its editable area.

This is set by HTMLEditorField - set the number of rows in your field.

Parameters

int $numRows

Return Value

HTMLEditorConfig

protected string getConfigType()

Get the string used to identify this config class in the CMS JavaScript.

Return Value

string