mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-76867 editor_tiny: Add plugin management page
This commit is contained in:
parent
51cfde0d3f
commit
e2de093fe8
@ -41,17 +41,17 @@ class manager {
|
||||
array $fpoptions = [],
|
||||
?editor $editor = null
|
||||
): array {
|
||||
$disabledplugins = $this->get_disabled_plugins();
|
||||
|
||||
// Get the list of plugins.
|
||||
// Note: Disabled plugins are already removed from this list.
|
||||
$plugins = $this->get_shipped_plugins();
|
||||
|
||||
// Fetch configuration for Moodle plugins.
|
||||
$moodleplugins = \core_component::get_plugin_list_with_class('tiny', 'plugininfo');
|
||||
$enabledplugins = \editor_tiny\plugininfo\tiny::get_enabled_plugins();
|
||||
foreach ($moodleplugins as $plugin => $classname) {
|
||||
if (in_array($plugin, $disabledplugins) || in_array("{$plugin}/plugin", $disabledplugins)) {
|
||||
// Skip getting data for disabled plugins.
|
||||
[, $pluginname] = explode('_', $plugin, 2);
|
||||
if (!in_array($pluginname, $enabledplugins)) {
|
||||
// This plugin has been disabled.
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -75,10 +75,6 @@ class manager {
|
||||
$editor
|
||||
);
|
||||
|
||||
if (!empty($config)) {
|
||||
$plugininfo['config'] = $config;
|
||||
}
|
||||
|
||||
// We suffix the plugin name for Moodle plugins with /plugin to avoid conflicts with Tiny plugins.
|
||||
$plugins["{$plugin}/plugin"] = $plugininfo;
|
||||
}
|
||||
@ -190,7 +186,7 @@ class manager {
|
||||
$plugins = $this->get_shipped_plugins();
|
||||
$plugins += $this->get_moodle_plugins();
|
||||
|
||||
$disabledplugins = $this->get_disabled_plugins();
|
||||
$disabledplugins = $this->get_disabled_tinymce_plugins();
|
||||
$plugins = array_filter($plugins, function ($plugin) use ($disabledplugins) {
|
||||
return !in_array($plugin, $disabledplugins);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
@ -216,8 +212,8 @@ class manager {
|
||||
$plugins += $this->get_premium_plugins();
|
||||
}
|
||||
|
||||
$disabledplugins = $this->get_disabled_plugins();
|
||||
return array_filter($plugins, function($plugin) use ($disabledplugins) {
|
||||
$disabledplugins = $this->get_disabled_tinymce_plugins();
|
||||
return array_filter($plugins, function ($plugin) use ($disabledplugins) {
|
||||
return !in_array($plugin, $disabledplugins);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
@ -480,11 +476,13 @@ class manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the disabled plugins.
|
||||
* Get a list of the built-in TinyMCE plugins which we want to disable.
|
||||
*
|
||||
* These are usually disabled because we have replaced them, or they are not compatible with Moodle in some way.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_disabled_plugins(): array {
|
||||
protected function get_disabled_tinymce_plugins(): array {
|
||||
return [
|
||||
// Disable the image and media plugins.
|
||||
// These are not generally compatible with Moodle.
|
||||
|
42
lib/editor/tiny/classes/table/plugin_management_table.php
Normal file
42
lib/editor/tiny/classes/table/plugin_management_table.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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/>.
|
||||
|
||||
namespace editor_tiny\table;
|
||||
|
||||
use moodle_url;
|
||||
|
||||
/**
|
||||
* Tiny admin settings.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class plugin_management_table extends \core_admin\table\plugin_management_table {
|
||||
protected function get_plugintype(): string {
|
||||
return 'tiny';
|
||||
}
|
||||
|
||||
public function guess_base_url(): void {
|
||||
$this->define_baseurl(
|
||||
new moodle_url('/admin/settings.php', ['section' => 'editorsettingstiny'])
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_action_url(array $params = []): moodle_url {
|
||||
return new moodle_url('/lib/editor/tiny/subplugins.php', $params);
|
||||
}
|
||||
}
|
@ -28,6 +28,8 @@ $string['settings'] = 'General settings';
|
||||
$string['privacy:reason'] = 'The TinyMCE editor does not store any preferences or user data.';
|
||||
$string['branding'] = 'TinyMCE branding';
|
||||
$string['branding_desc'] = 'Support TinyMCE by displaying the logo in the bottom corner of the text editor. The logo links to the TinyMCE website.';
|
||||
$string['plugin_enabled'] = 'The {$a} plugin has been enabled.';
|
||||
$string['plugin_disabled'] = 'The {$a} plugin has been disabled.';
|
||||
$string['tiny:hash'] = '#';
|
||||
$string['tiny:accessibility'] = 'Accessibility';
|
||||
$string['tiny:action'] = 'Action';
|
||||
|
@ -27,6 +27,13 @@ defined('MOODLE_INTERNAL') || die;
|
||||
$ADMIN->add('editorsettings', new admin_category('editortiny', $editor->displayname, $editor->is_enabled() === false));
|
||||
|
||||
$settings = new admin_settingpage('editorsettingstiny', new lang_string('settings', 'editor_tiny'));
|
||||
$settings->add(new \core_admin\admin\admin_setting_plugin_manager(
|
||||
'tiny',
|
||||
\editor_tiny\table\plugin_management_table::class,
|
||||
'editor_tiny_settings',
|
||||
get_string('editorsettings', 'editor'),
|
||||
));
|
||||
|
||||
if ($ADMIN->fulltree) {
|
||||
$setting = new admin_setting_configcheckbox(
|
||||
'editor_tiny/branding',
|
||||
@ -38,15 +45,15 @@ if ($ADMIN->fulltree) {
|
||||
$settings->add($setting);
|
||||
}
|
||||
|
||||
// Note: We add editortiny to the settings page here manually rather than deferring to the plugininfo class.
|
||||
// This ensures that it shows in the category list too.
|
||||
$ADMIN->add('editortiny', $settings);
|
||||
|
||||
foreach (core_plugin_manager::instance()->get_plugins_of_type('tiny') as $plugin) {
|
||||
/** @var \editor_tiny\plugininfo\tiny $plugin */
|
||||
$plugin->load_settings($ADMIN, 'editortiny', $hassiteconfig);
|
||||
}
|
||||
|
||||
// Note: We add editortiny to the settings page here manually rather than deferring to the plugininfo class.
|
||||
// This ensures that it shows in the category list too.
|
||||
$ADMIN->add('editortiny', $settings);
|
||||
|
||||
// Required or the editor plugininfo will add this section twice.
|
||||
unset($settings);
|
||||
$settings = null;
|
||||
|
63
lib/editor/tiny/subplugins.php
Normal file
63
lib/editor/tiny/subplugins.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Tiny subplugin management.
|
||||
*
|
||||
* @package editor_tinymce
|
||||
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require(__DIR__ . '/../../../config.php');
|
||||
require_once("{$CFG->libdir}/adminlib.php");
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$plugin = optional_param('plugin', '', PARAM_PLUGIN);
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_url('/lib/editor/tinymce/subplugins.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
require_sesskey();
|
||||
|
||||
$tinymanager = \core_plugin_manager::resolve_plugininfo_class('tiny');
|
||||
$pluginname = get_string('pluginname', "tiny_{$plugin}");
|
||||
|
||||
switch ($action) {
|
||||
case 'disable':
|
||||
if ($tinymanager::enable_plugin($plugin, 0)) {
|
||||
\core\notification::add(
|
||||
get_string('plugin_disabled', 'editor_tiny', $pluginname),
|
||||
\core\notification::SUCCESS
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'enable':
|
||||
if ($tinymanager::enable_plugin($plugin, 1)) {
|
||||
\core\notification::add(
|
||||
get_string('plugin_enabled', 'editor_tiny', $pluginname),
|
||||
\core\notification::SUCCESS
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
redirect(new moodle_url('/admin/settings.php', [
|
||||
'section' => 'editorsettingstiny',
|
||||
]));
|
30
lib/editor/tiny/tests/behat/manage_subplugins.feature
Normal file
30
lib/editor/tiny/tests/behat/manage_subplugins.feature
Normal file
@ -0,0 +1,30 @@
|
||||
@core @core_admin
|
||||
Feature: An administrator can manage TinyMCE subplugins
|
||||
In order to alter the user experience
|
||||
As an admin
|
||||
I can manage TinyMCE subplugins
|
||||
|
||||
@javascript
|
||||
Scenario: An administrator can control the enabled state of TinyMCE subplugins using JavaScript
|
||||
Given I am logged in as "admin"
|
||||
And I navigate to "Plugins > Text editors > TinyMCE > General settings" in site administration
|
||||
When I click on "Disable the Tiny equation editor plugin" "link"
|
||||
Then I should see "The Tiny equation editor plugin has been disabled"
|
||||
And "Disable the Tiny equation editor plugin" "link" should not exist
|
||||
But "Enable the Tiny equation editor plugin" "link" should exist
|
||||
When I click on "Enable the Tiny equation editor plugin" "link"
|
||||
Then I should see "The Tiny equation editor plugin has been enabled"
|
||||
And "Enable the Tiny equation editor plugin" "link" should not exist
|
||||
But "Disable the Tiny equation editor plugin" "link" should exist
|
||||
|
||||
Scenario: An administrator can control the enabled state of TinyMCE subplugins without JavaScript
|
||||
Given I am logged in as "admin"
|
||||
And I navigate to "Plugins > Text editors > TinyMCE > General settings" in site administration
|
||||
When I click on "Disable the Tiny equation editor plugin" "link"
|
||||
Then I should see "The Tiny equation editor plugin has been disabled"
|
||||
And "Disable the Tiny equation editor plugin" "link" should not exist
|
||||
But "Enable the Tiny equation editor plugin" "link" should exist
|
||||
When I click on "Enable the Tiny equation editor plugin" "link"
|
||||
Then I should see "The Tiny equation editor plugin has been enabled"
|
||||
And "Enable the Tiny equation editor plugin" "link" should not exist
|
||||
But "Disable the Tiny equation editor plugin" "link" should exist
|
@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2022112800; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2023021301; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2022111800;
|
||||
$plugin->component = 'editor_tiny'; // Full name of the plugin (used for diagnostics).
|
||||
|
Loading…
x
Reference in New Issue
Block a user