protected function render_single_button(single_button $button) { // Just because it says "single_botton" doesn't mean it's going to be rendered on its own // but it does mean it gets its own unique form and a div round it. $attributes = array('title' => $button->tooltip, 'class' => classes::add_to($button->class, 'btn btn-primary'), 'value' => $button->label, 'disabled' => $button->disabled ? 'disabled' : null); if ($button->actions) { $id = html_writer::random_id('single_button'); $attributes['id'] = $id; foreach ($button->actions as $action) { $this->add_action_handler($action, $id); } } $output = html::submit($attributes); if ($button->method === 'post') { $params['sesskey'] = sesskey(); } $output .= html::hidden_inputs($button->url->params()); if ($button->method === 'get') { $url = $button->url->out_omit_querystring(true); } else { $url = $button->url->out_omit_querystring(); } if ($url === '') { $url = '#'; } $attributes = array('method' => $button->method, 'action' => $url, 'id' => $button->formid); return html::form($attributes, $output); }
protected function disabled_navigation_node(navigation_node $node, $wrap = true) { $items = $node->children; if ($items->count() == 0) { return ''; } foreach ($items as $item) { if (!$item->display) { continue; } $isbranch = $item->children->count() > 0 || $item->nodetype == navigation_node::NODETYPE_BRANCH; if ($isbranch) { $item->hideicon = true; } $content = $this->output->render($item); $classes = 'tree_item'; $expanded = 'true'; if (!$item->forceopen || !$item->forceopen && $item->collapse || $item->children->count() == 0 && $item->nodetype == navigation_node::NODETYPE_BRANCH) { $classes = classes::add_to($classes, 'collapsed'); if ($isbranch) { $expanded = "false"; $classes = classes::add_to($classes, 'branch'); } } if ($item->isactive === true) { $classes = classes::add_to($classes, 'active'); } $attributes = array('class' => $classes, 'aria-expanded' => $expanded); $content .= $this->navigation_node($item); $lis[] = html::li($attributes, $content); } $output = implode($lis); if ($wrap) { return html::ul('nav nav-list block_tree', $output); } return $output; }
private function rewrite_tree_node($node_html, $new_classes) { $opening_tag = strstr($node_html, ' ', true); $pattern = '/class=\\"([^"]+)/'; if (preg_match($pattern, $node_html, $matches)) { $existing_classes = $matches[1]; $new_classes = classes::add_to($new_classes, $existing_classes); } $node_html = substr($node_html, strlen($opening_tag)); $node_html = substr($node_html, 0, -1 * strlen($opening_tag)); return '<a class="' . implode(' ', $new_classes) . '"' . $node_html . 'a>'; }
/** * @dataProvider add * @depends test_add */ public function test_create_class_key_on_add_to_array($first, $second, $expected) { $attributes = array(); $one_added = classes::add_to($attributes, $first); $this->assertArrayHasKey('class', $one_added); $two_added = classes::add_to($one_added, $second); $this->assertArrayHasKey('class', $two_added); $this->assertSame($expected, $two_added['class']); }
public static function submit($attributes) { $attributes['type'] = 'submit'; $attributes = classes::add_to($attributes, 'btn'); return self::input($attributes); }