forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-55384 theme_noname: Support tabs in theme settings
Part of MDL-55071
- Loading branch information
1 parent
d6d695b
commit 6bde945
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|