mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-52996 Atto: Allow plugins to customise toolbar
This commit is contained in:
parent
9d5d9c64ff
commit
f66da45fa5
4 changed files with 142 additions and 2 deletions
|
@ -69,6 +69,16 @@ class atto_texteditor extends texteditor {
|
|||
/**
|
||||
* Use this editor for given element.
|
||||
*
|
||||
* Available Atto-specific options:
|
||||
* atto:toolbar - set to a string to override the system config editor_atto/toolbar
|
||||
*
|
||||
* Available general options:
|
||||
* context - set to the current context object
|
||||
* enable_filemanagement - set false to get rid of the managefiles plugin
|
||||
* autosave - true/false to control autosave
|
||||
*
|
||||
* Options are also passed through to the plugins.
|
||||
*
|
||||
* @param string $elementid
|
||||
* @param array $options
|
||||
* @param null $fpoptions
|
||||
|
@ -76,7 +86,11 @@ class atto_texteditor extends texteditor {
|
|||
public function use_editor($elementid, array $options=null, $fpoptions=null) {
|
||||
global $PAGE;
|
||||
|
||||
$configstr = get_config('editor_atto', 'toolbar');
|
||||
if (array_key_exists('atto:toolbar', $options)) {
|
||||
$configstr = $options['atto:toolbar'];
|
||||
} else {
|
||||
$configstr = get_config('editor_atto', 'toolbar');
|
||||
}
|
||||
|
||||
$grouplines = explode("\n", $configstr);
|
||||
|
||||
|
|
36
lib/editor/atto/tests/behat/customtoolbar.feature
Normal file
36
lib/editor/atto/tests/behat/customtoolbar.feature
Normal file
|
@ -0,0 +1,36 @@
|
|||
@editor @editor_atto @atto
|
||||
Feature: Atto editor with customised toolbar
|
||||
In order to develop plugins that use Atto for specialised purposes
|
||||
As a developer
|
||||
I need to be able to configure Atto toolbar per-instance to include different plugins
|
||||
|
||||
Background:
|
||||
# Get to the fixture page.
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| label | L1 | <a href="../lib/editor/atto/tests/fixtures/custom_toolbar_example.php">FixtureLink</a> | C1 | label1 |
|
||||
When I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I follow "Course 1"
|
||||
And I follow "FixtureLink"
|
||||
|
||||
@javascript
|
||||
Scenario: Confirm that both editors have different toolbars but still function
|
||||
Given ".atto_link_button" "css_element" should exist in the ".normaldiv" "css_element"
|
||||
And ".atto_link_button" "css_element" should not exist in the ".specialdiv" "css_element"
|
||||
|
||||
When I set the field "normaleditor" to "Frogs"
|
||||
And I select the text in the "normaleditor" Atto editor
|
||||
And I click on ".atto_bold_button_bold" "css_element" in the ".normaldiv" "css_element"
|
||||
|
||||
And I set the field "specialeditor" to "Zombies"
|
||||
And I select the text in the "specialeditor" Atto editor
|
||||
And I click on ".atto_italic_button_italic" "css_element" in the ".specialdiv" "css_element"
|
||||
|
||||
And I press "Submit and see the HTML"
|
||||
|
||||
Then I should see "<b>Frogs</b>"
|
||||
And I should see "<i>Zombies</i>"
|
86
lib/editor/atto/tests/fixtures/custom_toolbar_example.php
vendored
Normal file
86
lib/editor/atto/tests/fixtures/custom_toolbar_example.php
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* Demonstrates use of Atto editor with overridden toolbar setting.
|
||||
*
|
||||
* This fixture is only used by the Behat test.
|
||||
*
|
||||
* @package editor_atto
|
||||
* @copyright 2016 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require(__DIR__ . '/../../../../../config.php');
|
||||
require_once($CFG->dirroot . '/lib/editor/atto/lib.php');
|
||||
|
||||
// Behat test fixture only.
|
||||
defined('BEHAT_SITE_RUNNING') || die('Only available on Behat test server');
|
||||
|
||||
$PAGE->set_url('/lib/editor/atto/tests/fixtures/override_plugins_example.php');
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// If this was sending some input, display it.
|
||||
$normal = optional_param('normaleditor', '', PARAM_RAW);
|
||||
$special = optional_param('specialeditor', '', PARAM_RAW);
|
||||
if ($normal !== '' || $special !== '') {
|
||||
echo html_writer::start_div('normalresult');
|
||||
echo s($normal);
|
||||
echo html_writer::end_div();
|
||||
echo html_writer::start_div('specialresult');
|
||||
echo s($special);
|
||||
echo html_writer::end_div();
|
||||
} else {
|
||||
// Create a form.
|
||||
echo html_writer::start_tag('form', array('method' => 'post', 'action' => 'custom_toolbar_example.php'));
|
||||
echo html_writer::start_div();
|
||||
|
||||
// Basic editor options.
|
||||
$options = array();
|
||||
$atto = new atto_texteditor();
|
||||
|
||||
// Normal Atto.
|
||||
echo html_writer::start_div('normaldiv');
|
||||
echo $OUTPUT->heading('Normal Atto');
|
||||
echo html_writer::div(html_writer::tag('textarea', '',
|
||||
array('id' => 'normaleditor', 'name' => 'normaleditor', 'rows' => 10)));
|
||||
$atto->use_editor('normaleditor', $options);
|
||||
echo html_writer::end_div();
|
||||
|
||||
// Second Atto with custom options.
|
||||
echo html_writer::start_div('specialdiv');
|
||||
$options['atto:toolbar'] = <<<EOT
|
||||
style1 = bold, italic
|
||||
list = unorderedlist, orderedlist
|
||||
EOT;
|
||||
echo $OUTPUT->heading('Special Atto');
|
||||
echo html_writer::div(html_writer::tag('textarea', '',
|
||||
array('id' => 'specialeditor', 'name' => 'specialeditor', 'rows' => 10)));
|
||||
$atto->use_editor('specialeditor', $options);
|
||||
echo html_writer::end_div();
|
||||
|
||||
// Button to submit form.
|
||||
echo html_writer::start_div('', array('style' => 'margin-top: 20px'));
|
||||
echo html_writer::tag('button', 'Submit and see the HTML');
|
||||
echo html_writer::end_div();
|
||||
|
||||
echo html_writer::end_div();
|
||||
echo html_writer::end_tag('form');
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
|
@ -225,8 +225,12 @@ abstract class texteditor {
|
|||
|
||||
/**
|
||||
* Add required JS needed for editor
|
||||
*
|
||||
* Valid options may vary by editor. See the individual editor
|
||||
* implementations of this function for documentation.
|
||||
*
|
||||
* @param string $elementid id of text area to be converted to editor
|
||||
* @param array $options
|
||||
* @param array $options Editor options
|
||||
* @param obejct $fpoptions file picker options
|
||||
* @return void
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue