Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
editor_tinymce_plugin Class Reference

Public Member Functions

 __construct ($plugin)
 
 get_buttons ()
 Returns list of buttons defined by this plugin. More...
 
 get_config ($name, $default=null)
 Returns plugin config value. More...
 
 get_name ()
 Returns name of this tinymce plugin. More...
 
 get_tinymce_file_url ($file='', $absolute=true)
 Returns URL to files in the TinyMCE folder within this plugin, suitable for client-side use such as loading JavaScript files. More...
 
 set_config ($name, $value)
 Sets plugin config value. More...
 

Static Public Member Functions

static all_update_init_params (array &$params, context $context, array $options=null)
 Calls all available plugins to adjust the TinyMCE init parameters. More...
 
static compare_plugins (editor_tinymce_plugin $a, editor_tinymce_plugin $b)
 Compares two plugins. More...
 
static get ($plugin)
 Gets a named plugin object. More...
 

Protected Member Functions

 add_button_after (array &$params, $row, $button, $after='', $alwaysadd=true)
 Adds a button to the editor, after another button (or at the end). More...
 
 add_button_before (array &$params, $row, $button, $before='', $alwaysadd=true)
 Adds a button to the editor. More...
 
 add_js_plugin (&$params, $pluginname='', $jsfile='editor_plugin.js')
 Adds a JavaScript plugin into TinyMCE. More...
 
 count_button_rows (array &$params)
 Counts the number of rows in TinyMCE editor (row numbering starts with 1) More...
 
 find_button (array &$params, $button)
 Tests if button is already present. More...
 
 get_sort_order ()
 Gets the order in which to run this plugin. More...
 
 get_version ()
 Obtains version number from version.php for this plugin. More...
 
 load_config ()
 Makes sure config is loaded and cached. More...
 
 update_init_params (array &$params, context $context, array $options=null)
 Adjusts TinyMCE init parameters for this plugin. More...
 

Protected Attributes

array $buttons = array()
 list of buttons defined by this plugin
 
array $config = null
 Plugin settings.
 
string $plugin
 Plugin folder.
 

Constructor & Destructor Documentation

◆ __construct()

editor_tinymce_plugin::__construct (   $plugin)
Parameters
string$pluginName of folder

Member Function Documentation

◆ add_button_after()

editor_tinymce_plugin::add_button_after ( array &  $params,
  $row,
  $button,
  $after = '',
  $alwaysadd = true 
)
protected

Adds a button to the editor, after another button (or at the end).

Specify the location of this button using the $after variable. If you leave this blank, the button will be added at the end.

If you want to try different possible locations depending on existing plugins you can set $alwaysadd to false and check the return value to see if it succeeded.

Note: button will not be added if it is already present in any row (separator is an exception).

The following example will add the button 'newbutton' after the 'existingbutton' if it exists or in the end of the last row otherwise:

if ($row = $this->find_button($params, 'existingbutton')) {
    $this->add_button_after($params, $row, 'newbutton', 'existingbutton');
} else {
    $this->add_button_after($params, $this->count_button_rows($params), 'newbutton');
}
Parameters
array$paramsTinyMCE init parameters array
int$rowRow to add button to (1 to 3)
string$buttonIdentifier of button/plugin
string$afterAdds button directly after the named plugin
bool$alwaysaddIf specified $after string not found, add at end
Return values
boolTrue if added or button already exists (in any row)

◆ add_button_before()

editor_tinymce_plugin::add_button_before ( array &  $params,
  $row,
  $button,
  $before = '',
  $alwaysadd = true 
)
protected

Adds a button to the editor.

Specify the location of this button using the $before variable. If you leave this blank, the button will be added at the start.

If you want to try different possible locations depending on existing plugins you can set $alwaysadd to false and check the return value to see if it succeeded.

Note: button will not be added if it is already present in any row (separator is an exception).

The following example will add the button 'newbutton' before the 'existingbutton' if it exists or in the end of the last row otherwise:

if ($row = $this->find_button($params, 'existingbutton')) {
    $this->add_button_before($params, $row, 'newbutton', 'existingbutton');
} else {
    $this->add_button_after($params, $this->count_button_rows($params), 'newbutton');
}
Parameters
array$paramsTinyMCE init parameters array
int$rowRow to add button to (1 to 10)
string$buttonIdentifier of button/plugin
string$beforeAdds button directly before the named plugin
bool$alwaysaddIf specified $before string not found, add at start
Return values
boolTrue if added or button already exists (in any row)

◆ add_js_plugin()

editor_tinymce_plugin::add_js_plugin ( $params,
  $pluginname = '',
  $jsfile = 'editor_plugin.js' 
)
protected

Adds a JavaScript plugin into TinyMCE.

Note that adding a plugin does not by itself add a button; you must do both.

If you leave $pluginname blank (default) it uses the folder name.

Parameters
array$paramsTinyMCE init parameters array
string$pluginnameIdentifier for plugin within TinyMCE
string$jsfileName of JS file (within plugin 'tinymce' directory)

◆ all_update_init_params()

static editor_tinymce_plugin::all_update_init_params ( array &  $params,
context  $context,
array  $options = null 
)
static

Calls all available plugins to adjust the TinyMCE init parameters.

Parameters
array$paramsTinyMCE init parameters array
context$contextContext where editor is being shown
array$optionsOptions for this editor

◆ compare_plugins()

static editor_tinymce_plugin::compare_plugins ( editor_tinymce_plugin  $a,
editor_tinymce_plugin  $b 
)
static

Compares two plugins.

Parameters
editor_tinymce_plugin$a
editor_tinymce_plugin$b
Return values
Negativenumber if $a is before $b

◆ count_button_rows()

editor_tinymce_plugin::count_button_rows ( array &  $params)
protected

Counts the number of rows in TinyMCE editor (row numbering starts with 1)

Parameters
array$paramsTinyMCE init parameters array
Return values
intthe maximum existing row number

◆ find_button()

editor_tinymce_plugin::find_button ( array &  $params,
  $button 
)
protected

Tests if button is already present.

Parameters
array$paramsTinyMCE init parameters array
string$buttonbutton name
Return values
false|intfalse if button is not found, row number otherwise (row numbers start from 1)

◆ get()

static editor_tinymce_plugin::get (   $plugin)
static

Gets a named plugin object.

Will cause fatal error if plugin doesn't exist.

Parameters
string$pluginName of plugin e.g. 'moodleemoticon'
Return values
editor_tinymce_pluginPlugin object

◆ get_buttons()

editor_tinymce_plugin::get_buttons ( )

Returns list of buttons defined by this plugin.

useful mostly as information when setting custom toolbar.

Return values
array

◆ get_config()

editor_tinymce_plugin::get_config (   $name,
  $default = null 
)

Returns plugin config value.

Parameters
string$name
string$defaultvalue if config does not exist yet
Return values
stringvalue or default

◆ get_name()

editor_tinymce_plugin::get_name ( )

Returns name of this tinymce plugin.

Return values
string

◆ get_sort_order()

editor_tinymce_plugin::get_sort_order ( )
protected

Gets the order in which to run this plugin.

Order usually only matters if (a) the place you add your button might depend on another plugin, or (b) you want to make some changes to layout etc. that should happen last. The default order is 100; within that, plugins are sorted alphabetically. Return a lower number if you want this plugin to run earlier, or a higher number if you want it to run later.

◆ get_tinymce_file_url()

editor_tinymce_plugin::get_tinymce_file_url (   $file = '',
  $absolute = true 
)

Returns URL to files in the TinyMCE folder within this plugin, suitable for client-side use such as loading JavaScript files.

(This URL normally goes through loader.php and contains the plugin version to ensure correct and long-term cacheing.)

Parameters
string$fileFilename or path within the folder
bool$absoluteSet false to get relative URL from plugins folder

◆ get_version()

editor_tinymce_plugin::get_version ( )
protected

Obtains version number from version.php for this plugin.

Return values
stringVersion number

◆ load_config()

editor_tinymce_plugin::load_config ( )
protected

Makes sure config is loaded and cached.

Return values
void

◆ set_config()

editor_tinymce_plugin::set_config (   $name,
  $value 
)

Sets plugin config value.

Parameters
string$namename of config
string$valuestring config value, null means delete
Return values
stringvalue

◆ update_init_params()

editor_tinymce_plugin::update_init_params ( array &  $params,
context  $context,
array  $options = null 
)
abstractprotected

Adjusts TinyMCE init parameters for this plugin.

Subclasses must implement this function in order to carry out changes to the TinyMCE settings.

Parameters
array$paramsTinyMCE init parameters array
context$contextContext where editor is being shown
array$optionsOptions for this editor

The documentation for this class was generated from the following file: