diff --git a/data/migratedPages.yml b/data/migratedPages.yml index 39451872ee..16a46ee8c0 100644 --- a/data/migratedPages.yml +++ b/data/migratedPages.yml @@ -124,6 +124,9 @@ Docs_required_issues_process: Documentation_credits: - filePath: "/general/community/credits/documentation.md" slug: "/general/community/credits/documentation" +Editor_API: +- filePath: "/docs/apis/subsystems/editor/index.md" + slug: "/docs/apis/subsystems/editor/" Enrolment_API: - filePath: "/docs/apis/subsystems/enrol.md" slug: "/docs/apis/subsystems/enrol" diff --git a/docs/apis.md b/docs/apis.md index 03ac35e0a4..455fa4fcb2 100644 --- a/docs/apis.md +++ b/docs/apis.md @@ -102,7 +102,7 @@ The [Data definition API](./apis/core/dml/ddl) is what you use to create, change ### Editor API -The [Editor API](https://docs.moodle.org/dev/Editor_API) is used to control HTML text editors. +The [Editor API](./apis/subsystems/editor/index.md) is used to control HTML text editors. ### Enrolment API (enrol) diff --git a/docs/apis/subsystems/editor/index.md b/docs/apis/subsystems/editor/index.md new file mode 100644 index 0000000000..bdb2afb1f1 --- /dev/null +++ b/docs/apis/subsystems/editor/index.md @@ -0,0 +1,54 @@ +--- +title: Editor API +tags: [] +documentationDraft: true +--- + +The editor API lets you control Moodle text editors. It can be found in `lib/editorlib.php`. + +:::important + +Normally you do not need to use this API directly because you can include editors as part of a Moodle form, which will automatically set up the editor for you. + +::: + +## How to set up a text editor + +To set up a text editor on an existing HTML text area field: + +- Call function `editors_get_preferred_editor()`, which will return an object of the texteditor class. +- Call function `use_editor()` to enable the editor for the text area. + +For example, assuming there is an HTML text area with id `mytextareaid`: + +```php +$editor = editors_get_preferred_editor(FORMAT_HTML); +$editor->use_editor('mytextareaid'); +``` + +## Editor options + +The use_editor function allows an options array to be supplied. + +### General options + +- `context`: set to the current context object +- `enable_filemanagement`: set false to disable the file management plugin +- `autosave`: set false to disable autosave + +### Atto-specific options + +- `toolbar`: set to override which icons appear on the toolbar (normally it uses the admin setting - this is for special cases for example if you want a minimal editor in a particular plugin). + +The following example will cause atto to show the four buttons indicated. + +```php +$attobuttons = 'style1 = bold, italic' . PHP_EOL . 'list = unorderedlist, orderedlist'; +$editor->use_editor($id, [ + 'context' => $context, + 'autosave' => false, + 'atto:toolbar' => $attobuttons +], [ + 'return_types' => FILE_EXTERNAL, +]); +``` diff --git a/project-words.txt b/project-words.txt index efacbe54ce..4f529d63bd 100644 --- a/project-words.txt +++ b/project-words.txt @@ -257,6 +257,7 @@ tablespace tasklogs templatable temptables +texteditor themers thirdparty thirdpartylibs