Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

(no description)

File Size: 476 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

editor_tinymce_plugin:: (18 methods):
  __construct()
  get_buttons()
  load_config()
  get_config()
  set_config()
  get_name()
  get_sort_order()
  add_button_after()
  add_button_before()
  find_button()
  fix_row()
  count_button_rows()
  add_js_plugin()
  get_tinymce_file_url()
  get_version()
  all_update_init_params()
  get()
  compare_plugins()


Class: editor_tinymce_plugin  - X-Ref

TinyMCE text editor plugin base class.

This is a base class for TinyMCE plugins implemented within Moodle. These
plugins can optionally provide new buttons/plugins within TinyMCE itself,
or configure the TinyMCE options.

As well as overridable functions, other utility functions in this class
can be used when writing the plugins.

Finally, a static function in this class is used to call into all the
plugins when required.

__construct($plugin)   X-Ref

param: string $plugin Name of folder

get_buttons()   X-Ref
Returns list of buttons defined by this plugin.
useful mostly as information when setting custom toolbar.

return: array

load_config()   X-Ref
Makes sure config is loaded and cached.

return: void

get_config($name, $default = null)   X-Ref
Returns plugin config value.

param: string $name
param: string $default value if config does not exist yet
return: string value or default

set_config($name, $value)   X-Ref
Sets plugin config value.

param: string $name name of config
param: string $value string config value, null means delete
return: string value

get_name()   X-Ref
Returns name of this tinymce plugin.

return: string

get_sort_order()   X-Ref
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.


add_button_after(array &$params, $row, $button,$after = '', $alwaysadd = true)   X-Ref
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:
<pre>
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');
}
</pre>

param: array $params TinyMCE init parameters array
param: int $row Row to add button to (1 to 3)
param: string $button Identifier of button/plugin
param: string $after Adds button directly after the named plugin
param: bool $alwaysadd If specified $after string not found, add at end
return: bool True if added or button already exists (in any row)

add_button_before(array &$params, $row, $button,$before = '', $alwaysadd = true)   X-Ref
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:
<pre>
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');
}
</pre>

param: array $params TinyMCE init parameters array
param: int $row Row to add button to (1 to 10)
param: string $button Identifier of button/plugin
param: string $before Adds button directly before the named plugin
param: bool $alwaysadd If specified $before string not found, add at start
return: bool True if added or button already exists (in any row)

find_button(array &$params, $button)   X-Ref
Tests if button is already present.

param: array $params TinyMCE init parameters array
param: string $button button name
return: false|int false if button is not found, row number otherwise (row numbers start from 1)

fix_row(array &$params, $row)   X-Ref
Checks the row value is valid, fix if necessary.

param: array $params TinyMCE init parameters array
param: int $row Row to add button if exists
return: int requested row if exists, lower number if does not exist.

count_button_rows(array &$params)   X-Ref
Counts the number of rows in TinyMCE editor (row numbering starts with 1)

param: array $params TinyMCE init parameters array
return: int the maximum existing row number

add_js_plugin(&$params, $pluginname='', $jsfile='editor_plugin.js')   X-Ref
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.

param: array $params TinyMCE init parameters array
param: string $pluginname Identifier for plugin within TinyMCE
param: string $jsfile Name of JS file (within plugin 'tinymce' directory)

get_tinymce_file_url($file='', $absolute=true)   X-Ref
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.)

param: string $file Filename or path within the folder
param: bool $absolute Set false to get relative URL from plugins folder

get_version()   X-Ref
Obtains version number from version.php for this plugin.

return: string Version number

all_update_init_params(array &$params,context $context, array $options = null)   X-Ref
Calls all available plugins to adjust the TinyMCE init parameters.

param: array $params TinyMCE init parameters array
param: context $context Context where editor is being shown
param: array $options Options for this editor

get($plugin)   X-Ref
Gets a named plugin object. Will cause fatal error if plugin doesn't exist.

param: string $plugin Name of plugin e.g. 'moodleemoticon'
return: editor_tinymce_plugin Plugin object

compare_plugins(editor_tinymce_plugin $a, editor_tinymce_plugin $b)   X-Ref
Compares two plugins.

param: editor_tinymce_plugin $a
param: editor_tinymce_plugin $b
return: Negative number if $a is before $b