mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-21198 towards origianl single_button() syntax + other improvements
This commit is contained in:
parent
87653d4027
commit
3cd5305f11
@ -1521,9 +1521,10 @@ class html_form extends html_component {
|
||||
* Constructor: sets up the other components in case they are needed
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct(array $options = null) {
|
||||
parent::__construct($options);
|
||||
$this->button = new html_button();
|
||||
$this->button->text = get_string('yes');
|
||||
$this->button->text = get_string('ok');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1547,14 +1548,14 @@ class html_form extends html_component {
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
|
||||
public static function make_button($url, array $params=null, $label=null, $method='post') {
|
||||
if ($label === null) {
|
||||
$label = get_string('ok');
|
||||
}
|
||||
$form = new html_form();
|
||||
public static function make_button($url, array $params=null, $label=null, $method='post', array $formoptions=null) {
|
||||
$form = new html_form($formoptions);
|
||||
$form->url = new moodle_url($url, $params);
|
||||
$form->button->text = $label;
|
||||
if ($label !== null) {
|
||||
$form->button->text = $label;
|
||||
}
|
||||
$form->method = $method;
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
@ -993,13 +993,34 @@ class core_renderer extends renderer_base {
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a form with single button.
|
||||
*
|
||||
* @param string|moodle_url|html_form $url_or_form
|
||||
* @param string $label button text
|
||||
* @param string $method get or post submit method
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function single_button($url_or_form, $label=null, $method='get') {
|
||||
if ($url_or_form instanceof html_form) {
|
||||
$form = clone($url_or_form);
|
||||
if (!is_null($label)) {
|
||||
$form->button->text = $label;
|
||||
}
|
||||
} else {
|
||||
$form = html_form::make_button($url_or_form, null, $label, $method);
|
||||
}
|
||||
|
||||
return $this->button($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a html_form object, outputs an <input> tag within a form that uses the object's attributes.
|
||||
*
|
||||
* @param html_form $form A html_form object
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function button($form) {
|
||||
public function button(html_form $form) {
|
||||
if (empty($form->button) or !($form->button instanceof html_button)) {
|
||||
throw new coding_exception('$OUTPUT->button($form) requires $form to have a button (html_button) value');
|
||||
}
|
||||
@ -1030,7 +1051,7 @@ class core_renderer extends renderer_base {
|
||||
* @param string $contents HTML fragment to put inside the form. If given, must contain at least the submit button.
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function form($form, $contents=null) {
|
||||
public function form(html_form $form, $contents=null) {
|
||||
$form = clone($form);
|
||||
$form->prepare($this, $this->page, $this->target);
|
||||
$this->prepare_event_handlers($form);
|
||||
|
Loading…
x
Reference in New Issue
Block a user