Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing Atto plugintype page for 4.1 #1286

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable first-line-heading -->
The plugin must implement a YUI module that will be included by the editor when the page loads.

That YUI module **must** be named `button` and must create a namespaced class in `Y.M.[plugin name]`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) Moodle Pty Ltd.
*
* Moodle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Moodle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';
import { ComponentFileSummary } from '../../../../_utils';
import type { Props } from '../../../../_utils';

const defaultExample = `Y.namespace('M.atto_media').Button = Y.Base.create(
'button',
Y.M.editor_atto.EditorPlugin,
[],
{
initializer: function() {
this.addButton({
callback: this._toggleMedia,
icon: 'e/media',
inlineFormat: true,

// Key code for the keyboard shortcut which triggers this button:
keys: '66',

// Watch the following tags and add/remove highlighting as appropriate:
tags: 'media'
});
},

_toggleMedia: function() {
// Handle the button click here.
// You can fetch any passed in parameters here as follows:
var langs = this.get('langs');
}
}, {
ATTRS: {
// If any parameters were defined in the 'params_for_js' function,
// they should be defined here for proper access.
langs: {
value: ['Default', 'Value']
}
}
}
);
`;
import ButtonDescription from './button.md';

export default (initialProps: Props): ComponentFileSummary => (
<ComponentFileSummary
// defaultDescription={DefaultDescription}
defaultExample={defaultExample}
defaultDescription={ButtonDescription}
plugintype="atto"
filepath="/yui/src/button/js/button.js"
filetype="js"
summary="Example Button JavaScript"
{...initialProps}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- markdownlint-disable first-line-heading -->
An optional file which can be used to implement optional component callbacks.

The available callbacks are:

- `atto_[pluginname]_strings_for_js` - To add strings required by the YUI code
- `atto_[pluginname]_params_for_js` - To get the parameters required to instantiate the plugin
37 changes: 37 additions & 0 deletions versioned_docs/version-4.1/apis/plugintypes/atto/_examples/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Initialise the js strings required for this plugin.
*/
function atto_media_strings_for_js(): void {
global $PAGE;

$PAGE->requires->strings_for_js([
'add',
'width',
], 'atto_media');
}

/**
* Sends the parameters to the JS module.
*
* @return array
*/
function atto_media_params_for_js(): array {
global $OUTPUT, $PAGE;
$currentlang = current_language();
$langsinstalled = get_string_manager()->get_list_of_translations(true);
$params = [
'langs' => [
'installed' => [],
],
];

foreach ($langsinstalled as $code => $name) {
$params['langs']['installed'][] = [
'lang' => $name,
'code' => $code,
'default' => $currentlang == $code,
];
}

return $params;
}
112 changes: 112 additions & 0 deletions versioned_docs/version-4.1/apis/plugintypes/atto/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
title: Atto
tags: []
---

<Since versions={["2.7"]} issueNumber="MDL-43841" />

Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](./../../subsystems/editor/index.md). Most of the code is written in JavaScript using YUI modules.

All of the buttons in Atto are implemented as Moodle subplugins. This means that the subplugins can do anything a subplugin can do including, using language strings, database tables, other JavaScript, and more.

:::caution Sunset of Atto

A new Editor was created for Moodle 4.1 and later using the latest version of TinyMCE.

It is likely that Atto will be removed in Moodle 4.6.

:::

## File structure

import {
Lang,
Lib,
VersionPHP,
} from '../../_files';
import Button from './_examples/button';

Atto plugins are located in the `/lib/editor/atto/plugins` directory.

Each plugin is in a separate subdirectory and consists of a number of _mandatory files_ and any other files the developer is going to use.

<details>
<summary>View an example directory layout for the `atto_media` plugin.</summary>

```console
lib/editor/atto/plugins/media
|-- db
| └-- upgrade.php
|-- lang
| └-- en
| └-- atto_media.php
|-- yui
| └-- src
| └-- button
| └-- atto_media.php
| ├── build.json
| ├── js
| │   └── button.js
| └── meta
| └── button.json
|-- settings.php
└-- version.php
```

</details>

Some of the important files for the Atto plugintype are described below. See the [common plugin files](../commonfiles) documentation for details of other files which may be useful in your plugin.

### version.php

<VersionPHP
plugintype="atto"
/>

### lib.php

import LibExample from '!!raw-loader!./_examples/lib.php';
import LibDescription from './_examples/lib.md';

<Lib
plugintype="atto"
pluginname="media"
description={LibDescription}
example={LibExample}
legacy={false}
optional
/>

### yui/src/button/*

<!-- markdownlint-disable no-inline-html -->

<Button
pluginname="media"
modulename="button"
/>

:::note

It is recommended that you extend the `EditorPlugin` class as described below.
See: [YUI/Modules](../../../guides/javascript/yui/modules.md) for more information about YUI modules.

:::

The plugin:

- **must** register a class at `Y.M.atto_PLUGINNAME.button`;
- **must** provide a constructor; and
- ***should*** extend [Y.M.editor_atto.EditorPlugin](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin.js).

#### EditorPlugin

It is up to the plugin author to decide how best to write their plugin, but it is highly advisable to extend `EditorPlugin` class, which provides a number of useful functions for dealing with the Editor, Toolbars, Keyboard Navigation, and other related areas.

Of particular interest are:

- [addBasicButton](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js#L293) - to add a basic button which directly uses document.execCommand with minimal effort;
- [addButton](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js#L161) - to add a button giving you a greater degree of control via your own callback;
- [addToolbarMenu](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js#L337) - to add a dropdown toolbar menu;
- [markUpdated](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin.js#L91) - should be called after making changes to the content area; and
- [getDialogue](https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/editor/atto/yui/src/editor/js/editor-plugin-dialogue.js#L54) - return a standard dialogue, creating one if it does not already exist.
2 changes: 1 addition & 1 deletion versioned_docs/version-4.3/apis/plugintypes/atto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: []

<Since versions={["2.7"]} issueNumber="MDL-43841" />

Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](https://docs.moodle.org/dev/Editors). Most of the code is written in JavaScript using YUI modules.
Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](./../../subsystems/editor/index.md). Most of the code is written in JavaScript using YUI modules.

All of the buttons in Atto are implemented as Moodle subplugins. This means that the subplugins can do anything a subplugin can do including, using language strings, database tables, other JavaScript, and more.

Expand Down
2 changes: 1 addition & 1 deletion versioned_docs/version-4.4/apis/plugintypes/atto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: []

<Since versions={["2.7"]} issueNumber="MDL-43841" />

Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](https://docs.moodle.org/dev/Editors). Most of the code is written in JavaScript using YUI modules.
Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](./../../subsystems/editor/index.md). Most of the code is written in JavaScript using YUI modules.

All of the buttons in Atto are implemented as Moodle subplugins. This means that the subplugins can do anything a subplugin can do including, using language strings, database tables, other JavaScript, and more.

Expand Down
2 changes: 1 addition & 1 deletion versioned_docs/version-4.5/apis/plugintypes/atto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: []

<Since versions={["2.7"]} issueNumber="MDL-43841" />

Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](https://docs.moodle.org/dev/Editors). Most of the code is written in JavaScript using YUI modules.
Atto is a JavaScript text editor built specifically for Moodle. It is the default text editor in Moodle from 2.7 onwards, and is implemented as a standard Moodle [text editor plugin](./../../subsystems/editor/index.md). Most of the code is written in JavaScript using YUI modules.

All of the buttons in Atto are implemented as Moodle subplugins. This means that the subplugins can do anything a subplugin can do including, using language strings, database tables, other JavaScript, and more.

Expand Down
Loading