Skip to content

Commit

Permalink
MDL-52167 admin: display dependencies in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
davosmith authored and sarjona committed Feb 26, 2019
1 parent d940855 commit 08163b2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions admin/templates/setting.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* element - The Element HTML
* forceltr - Force this element to be displayed LTR
* default - Default value
* dependenton - optional message listing the settings this one is dependent on
Example context (json):
{
Expand Down Expand Up @@ -68,5 +69,6 @@
<div class="form-defaultinfo text-muted {{#forceltr}}text-ltr{{/forceltr}}">{{{default}}}</div>
{{/default}}
<div class="form-description mt-3">{{{description}}}</div>
{{#dependenton}}<div class="form-dependenton mt-3 text-muted">{{{.}}}</div>{{/dependenton}}
</div>
</div>
1 change: 1 addition & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@
$string['sessioncookiepath'] = 'Cookie path';
$string['sessionhandling'] = 'Session handling';
$string['sessiontimeout'] = 'Timeout';
$string['settingdependenton'] = 'This setting may be hidden, based on the value of <strong>{$a}</strong>';
$string['settingfileuploads'] = 'File uploading is required for normal operation, please enable it in PHP configuration.';
$string['settingmemorylimit'] = 'Insufficient memory detected, please set higher memory limit in PHP settings.';
$string['settingsafemode'] = 'Moodle is not fully compatible with safe mode, please ask server administrator to turn it off. Running Moodle under safe mode is not supported, please expect various problems if you do so.';
Expand Down
33 changes: 33 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,17 @@ public function add($setting) {
*/
public function hide_if($settingname, $dependenton, $condition = 'notchecked', $value = '1') {
$this->dependencies[] = new admin_settingdependency($settingname, $dependenton, $condition, $value);

// Reformat the dependency name to the plugin | name format used in the display.
$dependenton = str_replace('/', ' | ', $dependenton);

// Let the setting know, so it can be displayed underneath.
$findname = str_replace('/', '', $settingname);
foreach ($this->settings as $name => $setting) {
if ($name === $findname) {
$setting->add_dependent_on($dependenton);
}
}
}

/**
Expand Down Expand Up @@ -1663,6 +1674,8 @@ abstract class admin_setting {
private $flags = array();
/** @var bool Whether this field must be forced LTR. */
private $forceltr = null;
/** @var array list of other settings that may cause this setting to be hidden */
private $dependenton = [];

/**
* Constructor
Expand Down Expand Up @@ -2032,6 +2045,22 @@ public function get_force_ltr() {
public function set_force_ltr($value) {
$this->forceltr = $value;
}

/**
* Add a setting to the list of those that could cause this one to be hidden
* @param string $dependenton
*/
public function add_dependent_on($dependenton) {
$this->dependenton[] = $dependenton;
}

/**
* Get a list of the settings that could cause this one to be hidden.
* @return array
*/
public function get_dependent_on() {
return $this->dependenton;
}
}

/**
Expand Down Expand Up @@ -8683,6 +8712,10 @@ function format_admin_setting($setting, $title='', $form='', $description='', $l
$context->error = $adminroot->errors[$context->fullname]->error;
}

if ($dependenton = $setting->get_dependent_on()) {
$context->dependenton = get_string('settingdependenton', 'admin', implode(', ', $dependenton));
}

$context->id = 'admin-' . $setting->name;
$context->title = highlightfast($query, $title);
$context->name = highlightfast($query, $context->name);
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/showhidesettings.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/amd/src/showhidesettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,18 @@ define(['jquery'], function($) {
});
}

/**
* Hide the 'this setting may be hidden' messages.
*/
function hideDependencyInfo() {
$('.form-dependenton').hide();
}

return {
init: function(opts) {
dependencies = opts.dependencies;
initHandlers();
hideDependencyInfo();
}
};
});
2 changes: 2 additions & 0 deletions theme/bootstrapbase/templates/core_admin/setting.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* element - The Element HTML
* forceltr - Force this element to be displayed LTR
* default - Default value
* dependenton - optional message listing the settings this one is dependent on
Example context (json):
{
Expand Down Expand Up @@ -66,4 +67,5 @@
{{/default}}
</div>
<div class="form-description">{{{description}}}</div>
{{#dependenton}}<div class="form-dependenton">{{{.}}}</div>{{/dependenton}}
</div>

0 comments on commit 08163b2

Please sign in to comment.