Commit 828788f0 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-29945 plugin management: don't show Uninstall links for required plugins.

parent 735de1c2
......@@ -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);
......
......@@ -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';
......
......@@ -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.
......@@ -468,6 +486,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 {
......@@ -613,6 +633,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 {
......@@ -672,10 +694,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;
}
}
......@@ -751,7 +788,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;
}
}
......@@ -1243,10 +1280,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);
}
}
......@@ -1363,6 +1400,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()));
}
}
......@@ -1375,10 +1417,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);
}
}
......@@ -1399,6 +1441,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()));
}
}
/**
......@@ -1410,10 +1457,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);
}
}
}
......
......@@ -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;}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment