Skip to content

Commit

Permalink
MDL-33041 (1) Add subplugin support for 'editor' plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou authored and skodak committed Aug 10, 2012
1 parent 87e9331 commit c57fc98
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
9 changes: 5 additions & 4 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@
function uninstall_plugin($type, $name) {
global $CFG, $DB, $OUTPUT;

// recursively uninstall all module subplugins first
if ($type === 'mod') {
if (file_exists("$CFG->dirroot/mod/$name/db/subplugins.php")) {
// recursively uninstall all module/editor subplugins first
if ($type === 'mod' || $type === 'editor') {
$base = get_component_directory($type . '_' . $name);
if (file_exists("$base/db/subplugins.php")) {
$subplugins = array();
include("$CFG->dirroot/mod/$name/db/subplugins.php");
include("$base/db/subplugins.php");
foreach ($subplugins as $subplugintype=>$dir) {
$instances = get_plugin_list($subplugintype);
foreach ($instances as $subpluginname => $notusedpluginpath) {
Expand Down
14 changes: 9 additions & 5 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7890,11 +7890,12 @@ function get_plugin_types($fullpaths=true) {
'theme' => 'theme', // this is a bit hacky, themes may be in $CFG->themedir too
);

$mods = get_plugin_list('mod');
foreach ($mods as $mod => $moddir) {
if (file_exists("$moddir/db/subplugins.php")) {
$subpluginowners = array_merge(array_values(get_plugin_list('mod')),
array_values(get_plugin_list('editor')));
foreach ($subpluginowners as $ownerdir) {
if (file_exists("$ownerdir/db/subplugins.php")) {
$subplugins = array();
include("$moddir/db/subplugins.php");
include("$ownerdir/db/subplugins.php");
foreach ($subplugins as $subtype=>$dir) {
$info[$subtype] = $dir;
}
Expand Down Expand Up @@ -7940,6 +7941,10 @@ function get_plugin_list($plugintype) {
// mod is an exception because we have to call this function from get_plugin_types()
$fulldirs[] = $CFG->dirroot.'/mod';

} else if ($plugintype === 'editor') {
// Exception also needed for editor for same reason.
$fulldirs[] = $CFG->dirroot . '/lib/editor';

} else if ($plugintype === 'theme') {
$fulldirs[] = $CFG->dirroot.'/theme';
// themes are special because they may be stored also in separate directory
Expand All @@ -7958,7 +7963,6 @@ function get_plugin_list($plugintype) {
}
$fulldirs[] = $fulldir;
}

$result = array();

foreach ($fulldirs as $fulldir) {
Expand Down
26 changes: 14 additions & 12 deletions lib/pluginlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function get_plugins($disablecache=false) {
* Returns list of plugins that define their subplugins and the information
* about them from the db/subplugins.php file.
*
* At the moment, only activity modules can define subplugins.
* At the moment, only activity modules and editors can define subplugins.
*
* @param bool $disablecache force reload, cache can be used otherwise
* @return array with keys like 'mod_quiz', and values the data from the
Expand All @@ -147,18 +147,20 @@ public function get_subplugins($disablecache=false) {

if ($disablecache or is_null($this->subpluginsinfo)) {
$this->subpluginsinfo = array();
$mods = get_plugin_list('mod');
foreach ($mods as $mod => $moddir) {
$modsubplugins = array();
if (file_exists($moddir . '/db/subplugins.php')) {
include($moddir . '/db/subplugins.php');
foreach ($subplugins as $subplugintype => $subplugintyperootdir) {
$subplugin = new stdClass();
$subplugin->type = $subplugintype;
$subplugin->typerootdir = $subplugintyperootdir;
$modsubplugins[$subplugintype] = $subplugin;
foreach (array('mod', 'editor') as $type) {
$owners = get_plugin_list('type');
foreach ($owners as $component => $ownerdir) {
$componentsubplugins = array();
if (file_exists($ownerdir . '/db/subplugins.php')) {
include($ownerdir . '/db/subplugins.php');
foreach ($subplugins as $subplugintype => $subplugintyperootdir) {
$subplugin = new stdClass();
$subplugin->type = $subplugintype;
$subplugin->typerootdir = $subplugintyperootdir;
$componentsubplugins[$subplugintype] = $subplugin;
}
$this->subpluginsinfo[$type . '_' . $component] = $componentsubplugins;
}
$this->subpluginsinfo['mod_' . $mod] = $modsubplugins;
}
}
}
Expand Down

0 comments on commit c57fc98

Please sign in to comment.