MDL-19756 Migrated print_heading_with_help
This commit is contained in:
@@ -3505,3 +3505,41 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Centered heading with attached help button (same title text)
|
||||
* and optional icon attached
|
||||
*
|
||||
* @deprecated since Moodle 2.0
|
||||
*
|
||||
* @param string $text The text to be displayed
|
||||
* @param string $helppage The help page to link to
|
||||
* @param string $module The module whose help should be linked to
|
||||
* @param string $icon Image to display if needed
|
||||
* @param bool $return If set to true output is returned rather than echoed, default false
|
||||
* @return string|void String if return=true nothing otherwise
|
||||
*/
|
||||
function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
|
||||
|
||||
// debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->textfield($field).');
|
||||
|
||||
global $OUTPUT;
|
||||
|
||||
$helpicon = new help_icon();
|
||||
$helpicon->page = $helppage;
|
||||
$helpicon->text = $text;
|
||||
$helpicon->module = $module;
|
||||
|
||||
// Extract the src from $icon if it exists
|
||||
if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
|
||||
$icon = $matches[1];
|
||||
}
|
||||
|
||||
$output = $OUTPUT->heading_with_help($helpicon, $icon);
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
} else {
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2583,6 +2583,22 @@ class moodle_core_renderer extends moodle_renderer_base {
|
||||
return $this->link($icon->link);
|
||||
}
|
||||
|
||||
/*
|
||||
* Centered heading with attached help button (same title text)
|
||||
* and optional icon attached
|
||||
* @param help_icon $helpicon A help_icon object
|
||||
* @param mixed $image An image URL or a html_image object
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function heading_with_help($helpicon, $image=false) {
|
||||
if (!($image instanceof html_image) && !empty($image)) {
|
||||
$htmlimage = new html_image();
|
||||
$htmlimage->src = $image;
|
||||
$image = $htmlimage;
|
||||
}
|
||||
return $this->container($this->image($image) . $this->heading($helpicon->text, 2, 'main help') . $this->help_icon($helpicon), 'heading-with-help');
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a help icon.
|
||||
*
|
||||
@@ -2679,6 +2695,10 @@ class moodle_core_renderer extends moodle_renderer_base {
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function image($image) {
|
||||
if ($image === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$image->prepare();
|
||||
|
||||
$this->prepare_event_handlers($image);
|
||||
@@ -4626,6 +4646,9 @@ class help_icon extends moodle_html_component {
|
||||
}
|
||||
$this->image->add_class('iconhelp');
|
||||
} else if (empty($this->image->src)) {
|
||||
if (!($this->image instanceof html_image)) {
|
||||
$this->image = new html_image();
|
||||
}
|
||||
$this->image->src = $OUTPUT->old_icon_url('help');
|
||||
}
|
||||
|
||||
|
||||
@@ -1206,4 +1206,28 @@ class moodle_core_renderer_test extends UnitTestCase {
|
||||
$html = $this->renderer->user_picture($userpic);
|
||||
$this->assert(new ContainsTagWithAttributes('a', array('title' => 'Test User', 'href' => $CFG->wwwroot.'/user/view.php?id=1&course=1')), $html);
|
||||
}
|
||||
|
||||
public function test_heading_with_help() {
|
||||
$originalicon = new help_icon();
|
||||
$originalicon->page = 'myhelppage';
|
||||
$originalicon->text = 'Cool help text';
|
||||
|
||||
$helpicon = clone($originalicon);
|
||||
$html = $this->renderer->heading_with_help($helpicon);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'heading-with-help'), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('span', 'class', 'helplink'), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('h2', 'class', 'main help'), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('img', array('class' => 'iconhelp image', 'src' => $this->renderer->old_icon_url('help'))), $html);
|
||||
$this->assert(new ContainsTagWithContents('h2', 'Cool help text'), $html);
|
||||
|
||||
$helpicon = clone($originalicon);
|
||||
$helpicon->image = false;
|
||||
|
||||
$html = $this->renderer->heading_with_help($helpicon);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'heading-with-help'), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('span', 'class', 'helplink'), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('h2', 'class', 'main help'), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('img', array('class' => 'iconhelp image', 'src' => $this->renderer->old_icon_url('help'))), $html);
|
||||
$this->assert(new ContainsTagWithContents('h2', 'Cool help text'), $html);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2255,30 +2255,6 @@ function build_navigation($extranavlinks, $cm = null) {
|
||||
return(array('newnav' => true, 'navlinks' => $navigation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Centered heading with attached help button (same title text)
|
||||
* and optional icon attached
|
||||
*
|
||||
* @param string $text The text to be displayed
|
||||
* @param string $helppage The help page to link to
|
||||
* @param string $module The module whose help should be linked to
|
||||
* @param string $icon Image to display if needed
|
||||
* @param bool $return If set to true output is returned rather than echoed, default false
|
||||
* @return string|void String if return=true nothing otherwise
|
||||
*/
|
||||
function print_heading_with_help($text, $helppage, $module='moodle', $icon='', $return=false) {
|
||||
$output = '<div class="heading-with-help">';
|
||||
$output .= '<h2 class="main help">'.$icon.$text.'</h2>';
|
||||
$output .= helpbutton($helppage, $text, $module, true, false, '', true);
|
||||
$output .= '</div>';
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
} else {
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print (or return) a collapisble region, that has a caption that can
|
||||
* be clicked to expand or collapse the region.
|
||||
|
||||
Reference in New Issue
Block a user