MDL-80571 tiny_premium: Premium plugins can be individually enabled

This commit is contained in:
David Woloszyn
2024-04-30 09:40:15 +10:00
parent 792698af00
commit ed42b2e92b
14 changed files with 620 additions and 64 deletions
@@ -19,6 +19,8 @@ namespace tiny_premium;
use context;
use editor_tiny\editor;
use editor_tiny\plugin;
use editor_tiny\plugin_with_configuration;
use tiny_premium\manager;
/**
* Tiny Premium plugin.
@@ -27,7 +29,7 @@ use editor_tiny\plugin;
* @copyright 2023 David Woloszyn <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plugininfo extends plugin {
class plugininfo extends plugin implements plugin_with_configuration {
/**
* Determine if the plugin should be enabled by checking the capability and if the Tiny Premium API key is set.
@@ -46,4 +48,24 @@ class plugininfo extends plugin {
): bool {
return has_capability('tiny/premium:accesspremium', $context) && (get_config('tiny_premium', 'apikey') != false);
}
/**
* Get a list of enabled Tiny Premium plugins set by the admin.
*
* @param context $context The context that the editor is used within
* @param array $options The options passed in when requesting the editor
* @param array $fpoptions The filepicker options passed in when requesting the editor
* @param editor|null $editor The editor instance in which the plugin is initialised
* @return array
*/
public static function get_plugin_configuration_for_context(
context $context,
array $options,
array $fpoptions,
?editor $editor = null
): array {
return [
'premiumplugins' => implode(',', manager::get_enabled_plugins()),
];
}
}