]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Migrated print_heading_with_help
authornicolasconnault <nicolasconnault>
Tue, 4 Aug 2009 15:15:11 +0000 (15:15 +0000)
committernicolasconnault <nicolasconnault>
Tue, 4 Aug 2009 15:15:11 +0000 (15:15 +0000)
lib/deprecatedlib.php
lib/outputlib.php
lib/simpletest/testoutputlib.php
lib/weblib.php

index 0200a40f209526e7c0a09ae8312cc746e7329f2a..63c40e2516ef7800c73cfe68e6edd36f6b2fb2d9 100644 (file)
@@ -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;
+    }
+}
index 324fba299a4a00ee3d935dda444a7cb8b22635d6..0ffa1c2fb91f62889b86ad03795f2c9bf3df1b26 100644 (file)
@@ -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');
         }
 
index 978625a573770e72af920251271e7fd510e768fe..5c3acbfce557fd2265efba59f360339baad19f9c 100644 (file)
@@ -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);
+    }
 }
index 3df29fd626aed87353716d03683972442f8e8de7..42e0776b67d95afa5d841e6c57303762891abd90 100644 (file)
@@ -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.