mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-19756 Added $disabled value to html_link, which will be true if the link's URL compares with the $PAGE->url (order of params doesn't matter). A disabled link will render as italicised text by default.
This commit is contained in:
parent
b0e90a0ccd
commit
a0ead5eb81
@ -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
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,6 +185,9 @@ a.useredit, a:hover.useredit, .blink {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.currentlink {
|
||||
font-style: italic;
|
||||
}
|
||||
/***
|
||||
*** Header
|
||||
***/
|
||||
|
Loading…
x
Reference in New Issue
Block a user