2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @package block_settings
21 * @copyright 2010 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 class block_settings_renderer
extends plugin_renderer_base
{
27 public function settings_tree(settings_navigation
$navigation) {
29 foreach ($navigation->children
as &$child) {
30 $child->preceedwithhr
= ($count!==0);
31 if ($child->display
) {
35 $navigationattrs = array(
36 'class' => 'block_tree list',
38 'data-ajax-loader' => 'block_navigation/site_admin_loader');
39 $content = $this->navigation_node($navigation, $navigationattrs);
40 if (isset($navigation->id
) && !is_numeric($navigation->id
) && !empty($content)) {
41 $content = $this->output
->box($content, 'block_tree_box', $navigation->id
);
47 * Build the navigation node.
49 * @param navigation_node $node the navigation node object.
50 * @param array $attrs list of attributes.
51 * @param int $depth the depth, default to 1.
52 * @return string the navigation node code.
54 protected function navigation_node(navigation_node
$node, $attrs=array(), $depth = 1) {
55 $items = $node->children
;
57 // exit if empty, we don't want an empty ul element
58 if ($items->count()==0) {
62 // array of nested li elements
65 foreach ($items as $item) {
67 if (!$item->display
) {
71 $isbranch = ($item->children
->count()>0 ||
$item->nodetype
==navigation_node
::NODETYPE_BRANCH
);
74 $item->hideicon
= true;
77 $content = $this->output
->render($item);
78 $id = $item->id ?
$item->id
: html_writer
::random_id();
79 $ulattr = ['id' => $id . '_group', 'role' => 'group'];
80 $liattr = ['class' => [$item->get_css_type(), 'depth_'.$depth], 'tabindex' => '-1'];
81 $pattr = ['class' => ['tree_item'], 'role' => 'treeitem'];
82 $pattr +
= !empty($item->id
) ?
['id' => $item->id
] : [];
83 $hasicon = (!$isbranch && $item->icon
instanceof renderable
);
86 $liattr['class'][] = 'contains_branch';
87 if (!$item->forceopen ||
(!$item->forceopen
&& $item->collapse
) ||
($item->children
->count() == 0
88 && $item->nodetype
== navigation_node
::NODETYPE_BRANCH
)) {
89 $pattr +
= ['aria-expanded' => 'false'];
91 $pattr +
= ['aria-expanded' => 'true'];
93 if ($item->requiresajaxloading
) {
94 $pattr['data-requires-ajax'] = 'true';
95 $pattr['data-loaded'] = 'false';
97 $pattr +
= ['aria-owns' => $id . '_group'];
99 } else if ($hasicon) {
100 $liattr['class'][] = 'item_with_icon';
101 $pattr['class'][] = 'hasicon';
103 if ($item->isactive
=== true) {
104 $liattr['class'][] = 'current_branch';
106 if (!empty($item->classes
) && count($item->classes
) > 0) {
107 $pattr['class'] = array_merge($pattr['class'], $item->classes
);
109 $nodetextid = 'label_' . $depth . '_' . $number;
111 // class attribute on the div item which only contains the item content
112 $pattr['class'][] = 'tree_item';
114 $pattr['class'][] = 'branch';
116 $pattr['class'][] = 'leaf';
119 $liattr['class'] = join(' ', $liattr['class']);
120 $pattr['class'] = join(' ', $pattr['class']);
122 if (isset($pattr['aria-expanded']) && $pattr['aria-expanded'] === 'false') {
123 $ulattr +
= ['aria-hidden' => 'true'];
126 $content = html_writer
::tag('p', $content, $pattr) . $this->navigation_node($item, $ulattr, $depth +
1);
127 if (!empty($item->preceedwithhr
) && $item->preceedwithhr
===true) {
128 $content = html_writer
::empty_tag('hr') . $content;
130 $liattr['aria-labelledby'] = $nodetextid;
131 $content = html_writer
::tag('li', $content, $liattr);
136 if (empty($attrs['role'])) {
137 $attrs['role'] = 'group';
139 return html_writer
::tag('ul', implode("\n", $lis), $attrs);
145 public function search_form(moodle_url
$formtarget, $searchvalue) {
147 'action' => $formtarget->out(false),
148 'label' => get_string('searchinsettings', 'admin'),
149 'searchvalue' => $searchvalue
151 return $this->render_from_template('block_settings/search_form', $data);