]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Added $disabled value to html_link, which will be true if the link's URL...
authornicolasconnault <nicolasconnault>
Wed, 9 Sep 2009 03:28:26 +0000 (03:28 +0000)
committernicolasconnault <nicolasconnault>
Wed, 9 Sep 2009 03:28:26 +0000 (03:28 +0000)
lib/outputcomponents.php
lib/outputrenderers.php
theme/standard/styles_fonts.css

index df9d76297af21240dcc5c6d1bbc7738969789f00..9ec7e55ed1631d5057151ad17ad0a7209f9885c8 100644 (file)
@@ -193,7 +193,7 @@ class moodle_html_component {
      * Shortcut for adding a JS confirm dialog when the component is clicked.
      * The message must be a yes/no question.
      * @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur.
-     * @param string $callback The name of a JS function whose scope will be set to the simpleDialog object and have this 
+     * @param string $callback The name of a JS function whose scope will be set to the simpleDialog object and have this
      *    function's arguments set as this.args.
      * @return void
      */
@@ -909,10 +909,10 @@ class html_field extends labelled_html_component {
      * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
      * @return html_field The field component
      */
-    public static function make_text($name='unnamed', $value, $alt='', $maxlength=0) {
+    public static function make_text($name='unnamed', $value='', $alt='', $maxlength=0) {
         $field = new html_field();
         if (empty($alt)) {
-            $alt = get_string('textfield');
+            $alt = $name;
         }
         $field->type = 'text';
         $field->name = $name;
@@ -939,7 +939,7 @@ class html_field extends labelled_html_component {
  */
 class html_table extends labelled_html_component {
     /**
-     * For more control over the rendering of the headers, an array of html_table_cell objects 
+     * For more control over the rendering of the headers, an array of html_table_cell objects
      * can be passed instead of an array of strings.
      * @var array of headings. The n-th array item is used as a heading of the n-th column.
      *
@@ -1072,7 +1072,7 @@ class html_table extends labelled_html_component {
      * @var array $footclasses Array of CSS classes to apply to the table's tfoot.
      */
     public $footclasses = array();
-    
+
 
     /**
      * @see moodle_html_component::prepare()
@@ -1169,7 +1169,7 @@ class html_table_row extends moodle_html_component {
     public function prepare() {
         parent::prepare();
     }
-    
+
     /**
      * Shortcut method for creating a row with an array of cells. Converts cells to html_table_cell objects.
      * @param array $cells
@@ -1255,15 +1255,28 @@ class html_link extends moodle_html_component {
     public $text;
 
     /**
-     * @see lib/moodle_html_component#prepare()
+     * @var boolean $disabled Whether or not this link is disabled (will be rendered as plain text)
+     */
+    public $disabled = false;
+
+    /**
+     * @see lib/moodle_html_component#prepare() Disables the link if it links to the current page.
      * @return void
      */
     public function prepare() {
+        global $PAGE;
         // We can't accept an empty text value
         if (empty($this->text)) {
             throw new coding_exception('A html_link must have a descriptive text value!');
         }
 
+        if (!($this->url instanceof moodle_url)) {
+            $this->url = new moodle_url($this->url);
+        }
+
+        if ($this->url->compare($PAGE->url, URL_MATCH_PARAMS)) {
+            $this->disabled = true;
+        }
         parent::prepare();
     }
 
@@ -1277,6 +1290,7 @@ class html_link extends moodle_html_component {
         $link = new html_link();
         $link->url = $url;
         $link->text = $text;
+
         return $link;
     }
 }
@@ -1595,7 +1609,7 @@ class html_list_item extends moodle_html_component {
 }
 
 /**
- * Component representing a span element. It has no special attributes, so 
+ * Component representing a span element. It has no special attributes, so
  * it is very low-level and can be used for styling and JS actions.
  *
  * @copyright 2009 Nicolas Connault
index 7b4350cd4753f68da6b5bd86dbf3748e56d307b4..a3e9e09081de4b7e50ba42c186a59e93564ced2d 100644 (file)
@@ -1068,6 +1068,12 @@ class moodle_core_renderer extends moodle_renderer_base {
 
             $link->prepare();
             $this->prepare_event_handlers($link);
+
+            // A disabled link is rendered as formatted text
+            if ($link->disabled) {
+                return $this->container($link->text, 'currentlink');
+            }
+
             $attributes['href'] = prepare_url($link->url);
             $attributes['class'] = $link->get_classes_string();
             $attributes['title'] = $link->title;
@@ -1542,6 +1548,8 @@ class moodle_core_renderer extends moodle_renderer_base {
                 $listitem->prepare();
                 $this->prepare_event_handlers($listitem);
                 $output .= $this->output_tag('li', array('class' => $listitem->get_classes_string()), $listitem->value) . "\n";
+            } else {
+                $output .= $this->output_tag('li', array(), $listitem) . "\n";
             }
         }
 
index 6675f060767919bdf18caca9b33029bb94a32fa7..c4c6dabe3946978dee5b66b88c129a2ee7afd4e3 100644 (file)
@@ -185,6 +185,9 @@ a.useredit, a:hover.useredit, .blink {
   cursor: help;
 }
 
+.currentlink {
+  font-style: italic;
+}
 /***
  *** Header
  ***/