Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace editor_tiny;
18
 
19
use context;
20
 
21
/**
22
 * Tiny Editor Plugin class.
23
 *
24
 * This class must be implemented by any Moodle plugin adding TinyMCE features.
25
 *
26
 * It should optionally implement the following interfaces:
27
 * - plugin_with_buttons: to add buttons to the TinyMCE toolbar
28
 * - plugin_with_menuitems
29
 * - plugin_with_configuration: to add configuration to the TinyMCE editor
30
 *
31
 * @package editor_tiny
32
 * @copyright  2021 Andrew Lyons <andrew@nicols.co.uk>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
abstract class plugin {
36
    /**
37
     * Whether the plugin is enabled
38
     *
39
     * @param context $context The context that the editor is used within
40
     * @param array $options The options passed in when requesting the editor
41
     * @param array $fpoptions The filepicker options passed in when requesting the editor
42
     * @param editor $editor The editor instance in which the plugin is initialised
43
     * @return boolean
44
     */
45
    public static function is_enabled(
46
        context $context,
47
        array $options,
48
        array $fpoptions,
49
        ?editor $editor = null
50
    ): bool {
51
        return true;
52
    }
53
 
54
    /**
55
     * Get the plugin information for the plugin.
56
     *
57
     * @param context $context The context that the editor is used within
58
     * @param array $options The options passed in when requesting the editor
59
     * @param array $fpoptions The filepicker options passed in when requesting the editor
60
     * @param editor $editor The editor instance in which the plugin is initialised
61
     * @return array
62
     */
63
    final public static function get_plugin_info(
64
        context $context,
65
        array $options,
66
        array $fpoptions,
67
        ?editor $editor = null
68
    ): array {
69
        $plugindata = [];
70
 
71
        if (is_a(static::class, plugin_with_buttons::class, true)) {
72
            $plugindata['buttons'] = static::get_available_buttons();
73
        }
74
 
75
        if (is_a(static::class, plugin_with_menuitems::class, true)) {
76
            $plugindata['menuitems'] = static::get_available_menuitems();
77
        }
78
 
79
        if (is_a(static::class, plugin_with_configuration::class, true)) {
80
            $plugindata['config'] = static::get_plugin_configuration_for_context($context, $options, $fpoptions, $editor);
81
        }
82
 
83
        return $plugindata;
84
    }
85
}