Skip to content

Commit

Permalink
MDL-55384 theme_noname: Support tabs in theme settings
Browse files Browse the repository at this point in the history
Part of MDL-55071
  • Loading branch information
ryanwyllie authored and danpoltawski committed Sep 23, 2016
1 parent d6d695b commit 6bde945
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
100 changes: 100 additions & 0 deletions theme/noname/classes/admin_settingspage_tabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package theme_noname
* @copyright 2016 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* @package theme_noname
* @copyright 2016 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class theme_noname_admin_settingspage_tabs extends admin_settingpage {

/** @var The tabs */
protected $tabs = array();

/**
* Add a tab.
*
* @param admin_settingpage $tab A tab.
*/
public function add_tab(admin_settingpage $tab) {
foreach ($tab->settings as $setting) {
$this->settings->{$setting->name} = $setting;
}
$this->tabs[] = $tab;
return true;
}

public function add($tab) {
return $this->add_tab($tab);
}

/**
* Get tabs.
*
* @return array
*/
public function get_tabs() {
return $this->tabs;
}

/**
* Generate the HTML output.
*
* @return string
*/
public function output_html() {
global $OUTPUT;

$activetab = optional_param('activetab', '', PARAM_TEXT);
$context = array('tabs' => array());
$havesetactive = false;

foreach ($this->get_tabs() as $tab) {
$active = false;

// Default to first tab it not told otherwise.
if (empty($activetab) && !$havesetactive) {
$active = true;
$havesetactive = true;
} else if ($activetab === $tab->name) {
$active = true;
}

$context['tabs'][] = array(
'name' => $tab->name,
'displayname' => $tab->visiblename,
'html' => $tab->output_html(),
'active' => $active,
);
}

if (empty($context['tabs'])) {
return '';
}

return $OUTPUT->render_from_template('theme_noname/admin_setting_tabs', $context);
}

}

34 changes: 34 additions & 0 deletions theme/noname/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package theme_noname
* @copyright 2016 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

if ($ADMIN->fulltree) {

$settings = new theme_noname_admin_settingspage_tabs('theme_noname', 'CONFIG TITLE');
$temp = new admin_settingpage('theme_noname_general', 'GENERAL SETTINGS');

$settings->add($temp);
$temp = new admin_settingpage('theme_noname_advanced', 'ADVANCED');

$settings->add($temp);
}
31 changes: 31 additions & 0 deletions theme/noname/templates/admin_setting_tabs.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
<ul class="nav nav-tabs">
{{#tabs}}
<li class="nav-item">
<a href="#{{name}}" class="nav-link {{#active}}active{{/active}}" data-toggle="tab" role="tab">{{displayname}}</a>
</li>
{{/tabs}}
</ul>
<div class="tab-content m-t-1">
{{#tabs}}
<div class="tab-pane {{#active}}active{{/active}}" id="{{name}}" role="tabpanel">
{{{html}}}
</div>
{{/tabs}}
</div>

0 comments on commit 6bde945

Please sign in to comment.