MDL-41847 core_user: Add lang to login URL email for new user accounts
[moodle.git] / blocks / settings / renderer.php
blob34e99ef7d93d3d57393d40f01bf2612325b6f8fb
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Settings block
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) {
28 $count = 0;
29 foreach ($navigation->children as &$child) {
30 $child->preceedwithhr = ($count!==0);
31 if ($child->display) {
32 $count++;
35 $navigationattrs = array(
36 'class' => 'block_tree list',
37 'role' => 'tree',
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);
43 return $content;
46 /**
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) {
59 return '';
62 // array of nested li elements
63 $lis = array();
64 $number = 0;
65 foreach ($items as $item) {
66 $number++;
67 if (!$item->display) {
68 continue;
71 $isbranch = ($item->children->count()>0 || $item->nodetype==navigation_node::NODETYPE_BRANCH);
73 if ($isbranch) {
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);
85 if ($isbranch) {
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'];
90 } else {
91 $pattr += ['aria-expanded' => 'true'];
93 if ($item->requiresajaxloading) {
94 $pattr['data-requires-ajax'] = 'true';
95 $pattr['data-loaded'] = 'false';
96 } else {
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';
113 if ($isbranch) {
114 $pattr['class'][] = 'branch';
115 } else {
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);
132 $lis[] = $content;
135 if (count($lis)) {
136 if (empty($attrs['role'])) {
137 $attrs['role'] = 'group';
139 return html_writer::tag('ul', implode("\n", $lis), $attrs);
140 } else {
141 return '';
145 public function search_form(moodle_url $formtarget, $searchvalue) {
146 $content = html_writer::start_tag('form', array('class'=>'adminsearchform', 'method'=>'get', 'action'=>$formtarget, 'role' => 'search'));
147 $content .= html_writer::start_tag('div');
148 $content .= html_writer::tag('label', s(get_string('searchinsettings', 'admin')), array('for'=>'adminsearchquery', 'class'=>'accesshide'));
149 $content .= html_writer::empty_tag('input', array('id'=>'adminsearchquery', 'type'=>'text', 'name'=>'query', 'value'=>s($searchvalue)));
150 $content .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>s(get_string('search'))));
151 $content .= html_writer::end_tag('div');
152 $content .= html_writer::end_tag('form');
153 return $content;