Skip to content

Commit

Permalink
Remove previous unused settings, add enable menu control
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarat87 committed Dec 6, 2024
1 parent ef5ffb9 commit e3c637d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 101 deletions.
7 changes: 6 additions & 1 deletion classes/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ public static function before_standard_top_of_body_html_generation(before_standa
*/
public static function extend_user_menu(extend_user_menu $hook): void {
global $CFG;
$prodwwwroot = envbarlib::getprodwwwroot();

$config = get_config('local_envbar');
if (empty($config->enablemenu)) {
return;
}

$prodwwwroot = envbarlib::getprodwwwroot();
// Do not display on the production environment!
if ($prodwwwroot === $CFG->wwwroot) {
return;
Expand Down
4 changes: 0 additions & 4 deletions lang/en/local_envbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
$string['debuggingon'] = 'Debugging On';
$string['debugtogglelinkoff'] = 'Turn Off';
$string['debugtogglelinkon'] = 'Turn On';
$string['dividerselector'] = 'Divider selector';
$string['dividerselector_desc'] = 'This is a css class that is used for the menu divider element. If your theme uses different html then you may need to adjust this selector.<br />This setting is only used if the environment swapper menu is enabled.';
$string['emailheading'] = 'Email prefix';
$string['enableemailprefix'] = 'Enable email subject prefixing';
$string['enableemailprefix_desc'] = 'This setting controls if email subject fields will be prefixed with the first 4 letters of the environment\'s name or not.';
Expand All @@ -64,8 +62,6 @@
$string['menuheading'] = 'Environment swapper menu';
$string['menulastrefresh'] = 'Last refresh';
$string['menupresentation'] = 'Presentation';
$string['menuselector'] = 'Menu selector';
$string['menuselector_desc'] = 'This is a css or xpath selector to find the menu ul element for injecting the env swapper menu. If your theme uses different html then you may need to adjust this selector.<br />This setting is only used if the environment swapper menu is enabled.';
$string['missing_required_parameter'] = 'A required parameter was missing. Required params are wwwroot and lastrefresh.';
$string['nextrefreshin'] = 'Reset in {$a}';
$string['notconfigured'] = 'UNKNOWN';
Expand Down
84 changes: 0 additions & 84 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public function render_envbar($match, $fixed = true, $envs = array()) {

if ($fixed) {
$js .= local_envbar_favicon_js($match);
$js .= local_envbar_user_menu($envs, $match);
$js .= local_envbar_title($match);
}

Expand Down Expand Up @@ -384,86 +383,3 @@ function local_envbar_favicon_js($match) {

return $js;
}

/**
* Gets some JS which inserts env jump links into the user menu
*
* @param array $envs
* @return string A chunk of JS
*/
function local_envbar_user_menu($envs) {

global $CFG, $PAGE;

$config = get_config('local_envbar');

if (empty($config->enablemenu)) {
return '';
}

if (isset($config->menuselector)) {
$menuselector = $config->menuselector;
} else {
$menuselector = '.usermenu .menu';
}

if (empty($menuselector)) {
return ''; // Not using user menu, nothing to do.
}

$html = '';

if ($PAGE->has_set_url()) {
$url = $PAGE->url->out();

foreach ($envs as $env) {
$jump = $url;
$jump = str_replace($CFG->wwwroot, $env->matchpattern, $jump);
if ($jump == $url) {
continue;
}
$jump = s($jump);
$show = s($env->showtext);
$link = <<<EOD
<li role="presentation">
<a class="icon menu-action no-envbar-highlight" role="menuitem" href="{$jump}">
<span class="menu-action-text">$show</span>
</a>
</li>
EOD;
$html .= $link;
}
}

if (!$html) {
return '';
}

if (isset($config->dividerselector)) {
$divider = $config->dividerselector;
} else {
$divider = 'filler';
}
$html = '<li role="presentation"><span class="'. $divider .'">&nbsp;</span></li>' . $html;

$html = str_replace("\n", '', $html);
$html = str_replace("\"", "\\\"", $html);

$url = (new moodle_url('/admin/settings.php?section=local_envbar_presentation'))->out();
$isadmin = (is_siteadmin() ) ? '1' : '0';

$js = <<<EOD
var menu = document.querySelector('$menuselector');
var html = "$html";
if (menu) {
menu.insertAdjacentHTML('beforeend', html);
} else {
$isadmin && console.error(
"local_envbar: Menu selector is misconfigured '$menuselector' \\n Please configure it here: $url");
}
EOD;
return $js;

}

12 changes: 0 additions & 12 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@
get_string('enablemenu_desc', 'local_envbar', null, true),
true));

$presentation->add(new admin_setting_configtext('local_envbar/menuselector',
get_string('menuselector', 'local_envbar', null, true),
get_string('menuselector_desc', 'local_envbar', null, true),
'.usermenu .menu',
PARAM_RAW));

$presentation->add(new admin_setting_configtext('local_envbar/dividerselector',
get_string('dividerselector', 'local_envbar', null, true),
get_string('dividerselector_desc', 'local_envbar', null, true),
'filler',
PARAM_RAW));

$presentation->add(new admin_setting_heading('local_envbar/linksheading',
get_string('linksheading', 'local_envbar', null, true),
''));
Expand Down

0 comments on commit e3c637d

Please sign in to comment.