diff --git a/admin/renderer.php b/admin/renderer.php index be5780bf2c8..8c56d26e956 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -725,8 +725,12 @@ class core_admin_renderer extends plugin_renderer_base { } $uninstallurl = $plugin->get_uninstall_url(); + $requriedby = $pluginman->other_plugins_that_require($plugin->component); if (is_null($uninstallurl)) { $uninstall = new html_table_cell(''); + } else if ($requriedby) { + $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby))); + $uninstall->attributes['class'] = 'requiredby'; } else { $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin')); $uninstall = new html_table_cell($uninstall); diff --git a/lang/en/plugin.php b/lang/en/plugin.php index f43e0afd0bb..45ded8024ed 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -40,6 +40,7 @@ $string['plugindisable'] = 'Disable'; $string['plugindisabled'] = 'Disabled'; $string['pluginenable'] = 'Enable'; $string['pluginenabled'] = 'Enabled'; +$string['requiredby'] = 'Required by: {$a}'; $string['requires'] = 'Requires'; $string['rootdir'] = 'Directory'; $string['settings'] = 'Settings'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 1300416890d..17ea60ebc7e 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -229,6 +229,24 @@ class plugin_manager { } } + /** + * Get a list of any other pluings that require this one. + * @param string $component frankenstyle component name. + * @return array of frankensyle component names that require this one. + */ + public function other_plugins_that_require($component) { + $others = array(); + foreach ($this->get_plugins() as $type => $plugins) { + foreach ($plugins as $plugin) { + $required = $plugin->get_other_required_plugins(); + if (isset($required[$component])) { + $others[] = $plugin->component; + } + } + } + return $others; + } + /** * Check a dependencies list against the list of installed plugins. * @param array $dependencies compenent name to required version or ANY_VERSION. @@ -469,6 +487,8 @@ class plugin_manager { * Note that most of the useful information is made available in pubic fields, * which cannot be documented in this interface. See the field definitions on * {@link plugintype_base} to find out what information is available. + * + * @property-read string component the component name, type_name */ interface plugin_information { @@ -614,6 +634,8 @@ interface plugin_information { /** * Defines public properties that all plugintype classes must have * and provides default implementation of required methods. + * + * @property-read string component the component name, type_name */ abstract class plugintype_base { @@ -673,10 +695,25 @@ abstract class plugintype_base { * @see plugin_information::init_display_name() */ public function init_display_name() { - if (! get_string_manager()->string_exists('pluginname', $this->type . '_' . $this->name)) { - $this->displayname = '[pluginname,' . $this->type . '_' . $this->name . ']'; + if (!get_string_manager()->string_exists('pluginname', $this->component)) { + $this->displayname = '[pluginname,' . $this->component . ']'; } else { - $this->displayname = get_string('pluginname', $this->type . '_' . $this->name); + $this->displayname = get_string('pluginname', $this->component); + } + } + + /** + * Magic method getter, redirects to read only values. + * @param string $name + * @return mixed + */ + public function __get($name) { + switch ($name) { + case 'component': return $this->type . '_' . $this->name; + + default: + debugging('Invalid plugin property accessed! '.$name); + return null; } } @@ -752,7 +789,7 @@ abstract class plugintype_base { */ public function load_db_version() { - if ($ver = self::get_version_from_config_plugins($this->type . '_' . $this->name)) { + if ($ver = self::get_version_from_config_plugins($this->component)) { $this->versiondb = $ver; } } @@ -1244,10 +1281,10 @@ class plugintype_mod extends plugintype_base implements plugin_information { * @see plugin_information::init_display_name() */ public function init_display_name() { - if (get_string_manager()->string_exists('pluginname', $this->type . '_' . $this->name)) { - $this->displayname = get_string('pluginname', $this->type . '_' . $this->name); + if (get_string_manager()->string_exists('pluginname', $this->component)) { + $this->displayname = get_string('pluginname', $this->component); } else { - $this->displayname = get_string('modulename', $this->type . '_' . $this->name); + $this->displayname = get_string('modulename', $this->component); } } @@ -1364,6 +1401,11 @@ class plugintype_qbehaviour extends plugintype_base implements plugin_informatio $this->dependencies['qbehaviour_' . $other] = ANY_VERSION; } } + + public function get_uninstall_url() { + return new moodle_url('/admin/qbehaviours.php', + array('delete' => $this->name, 'sesskey' => sesskey())); + } } @@ -1376,10 +1418,10 @@ class plugintype_qtype extends plugintype_base implements plugin_information { * @see plugin_information::init_display_name() */ public function init_display_name() { - if (get_string_manager()->string_exists('pluginname', $this->type . '_' . $this->name)) { - $this->displayname = get_string('pluginname', $this->type . '_' . $this->name); + if (get_string_manager()->string_exists('pluginname', $this->component)) { + $this->displayname = get_string('pluginname', $this->component); } else { - $this->displayname = get_string($this->name, 'qtype_' . $this->name); + $this->displayname = get_string($this->name, $this->component); } } @@ -1400,6 +1442,11 @@ class plugintype_qtype extends plugintype_base implements plugin_information { $this->dependencies['qtype_' . $other] = ANY_VERSION; } } + + public function get_uninstall_url() { + return new moodle_url('/admin/qtypes.php', + array('delete' => $this->name, 'sesskey' => sesskey())); + } } /** @@ -1411,10 +1458,10 @@ class plugintype_qformat extends plugintype_base implements plugin_information { * @see plugin_information::init_display_name() */ public function init_display_name() { - if (get_string_manager()->string_exists('pluginname', $this->type . '_' . $this->name)) { - $this->displayname = get_string('pluginname', $this->type . '_' . $this->name); + if (get_string_manager()->string_exists('pluginname', $this->component)) { + $this->displayname = get_string('pluginname', $this->component); } else { - $this->displayname = get_string($this->name, 'qformat_' . $this->name); + $this->displayname = get_string($this->name, $this->component); } } } diff --git a/theme/base/style/admin.css b/theme/base/style/admin.css index 37279c06696..51c32e80363 100644 --- a/theme/base/style/admin.css +++ b/theme/base/style/admin.css @@ -193,11 +193,10 @@ #page-admin-index #plugins-check .status-upgrade .status {background-color:#d2ebff;} #page-admin-index #plugins-check .status-uptodate .status {color:#999;} #page-admin-index #plugins-check .requires ul {font-size:0.7em;margin:0;} -#page-admin-index #plugins-check .requires li {display:block;;} +#page-admin-index #plugins-check .requires li {display:block;} #page-admin-index #plugins-check .requires-ok {color:#999;} #page-admin-index #plugins-check .requires-failed {background-color:#ffd3d9;} - /** Plugins management */ #page-admin-plugins #plugins-control-panel {margin-left:auto; margin-right:auto;} #page-admin-plugins #plugins-control-panel .displayname .pluginicon {width:16px;} @@ -205,3 +204,4 @@ #page-admin-plugins #plugins-control-panel .disabled .availability {background-color:#eee;} #page-admin-plugins #plugins-control-panel .extension .source {background-color:#f3f2aa;} #page-admin-plugins #plugins-control-panel .msg td {text-align:center;} +#page-admin-plugins #plugins-control-panel .requiredby {font-size:0.7em;color:#999;}