mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 11:46:19 +01:00
MDL-15402: when an instance is reaonly, the administrator cannot delete it but should be able to modify the name (only)
This commit is contained in:
parent
ce2066a1c2
commit
1e97f196a4
@ -43,10 +43,6 @@ $return = true;
|
||||
if (!empty($edit) || !empty($new)) {
|
||||
if (!empty($edit)) {
|
||||
$instance = repository_get_instance($edit);
|
||||
//if you try to edit an instance set as readonly, display an error message
|
||||
if ($instance->readonly) {
|
||||
throw new repository_exception('readonlyinstance', 'repository');
|
||||
}
|
||||
$instancetype = repository_get_type_by_id($instance->typeid);
|
||||
$classname = 'repository_' . $instancetype->get_typename();
|
||||
$configs = $instance->get_instance_option_names();
|
||||
@ -72,8 +68,10 @@ if (!empty($edit) || !empty($new)) {
|
||||
if ($edit) {
|
||||
$settings = array();
|
||||
$settings['name'] = $fromform->name;
|
||||
foreach($configs as $config) {
|
||||
$settings[$config] = $fromform->$config;
|
||||
if (!$instance->readonly) {
|
||||
foreach($configs as $config) {
|
||||
$settings[$config] = $fromform->$config;
|
||||
}
|
||||
}
|
||||
$success = $instance->set_option($settings);
|
||||
} else {
|
||||
|
@ -1248,26 +1248,36 @@ final class repository_instance_form extends moodleform {
|
||||
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
|
||||
$mform->addRule('name', $strrequired, 'required', null, 'client');
|
||||
|
||||
//add fields
|
||||
if (!$this->instance) {
|
||||
$result = repository_static_function($this->plugin, 'instance_config_form', $mform);
|
||||
} else {
|
||||
$result = $this->instance->instance_config_form($mform);
|
||||
}
|
||||
|
||||
// and set the data if we have some.
|
||||
if ($this->instance) {
|
||||
$data = array();
|
||||
$data['name'] = $this->instance->name;
|
||||
foreach ($this->instance->get_instance_option_names() as $config) {
|
||||
if (!empty($this->instance->$config)) {
|
||||
$data[$config] = $this->instance->$config;
|
||||
} else {
|
||||
$data[$config] = '';
|
||||
}
|
||||
if (!$this->instance->readonly) {
|
||||
//add fields
|
||||
if (!$this->instance) {
|
||||
$result = repository_static_function($this->plugin, 'instance_config_form', $mform);
|
||||
} else {
|
||||
$result = $this->instance->instance_config_form($mform);
|
||||
}
|
||||
|
||||
// and set the data if we have some.
|
||||
if ($this->instance) {
|
||||
$data = array();
|
||||
$data['name'] = $this->instance->name;
|
||||
foreach ($this->instance->get_instance_option_names() as $config) {
|
||||
if (!empty($this->instance->$config)) {
|
||||
$data[$config] = $this->instance->$config;
|
||||
} else {
|
||||
$data[$config] = '';
|
||||
}
|
||||
}
|
||||
$this->set_data($data);
|
||||
}
|
||||
$this->set_data($data);
|
||||
}
|
||||
else {
|
||||
if ($this->instance) {
|
||||
$data = array();
|
||||
$data['name'] = $this->instance->name;
|
||||
$this->set_data($data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->add_action_buttons(true, get_string('save','repository'));
|
||||
}
|
||||
|
||||
@ -1396,8 +1406,8 @@ function repository_display_instances_list($context, $typename = null) {
|
||||
foreach ($instances as $i) {
|
||||
$settings = '';
|
||||
$delete = '';
|
||||
$settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
|
||||
if (!$i->readonly) {
|
||||
$settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
|
||||
$delete .= '<a href="' . $baseurl . '&type='.$typename.'&delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user