weekly release 3.2.1+
[moodle.git] / lib / form / warning.php
blobfe7ec66ab5b7c22ffa0b4ac4351f2d5c3c51230b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * static warning element
21 * Contains class for static warning type element
23 * @package core_form
24 * @copyright 2008 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once("HTML/QuickForm/static.php");
28 require_once('templatable_form_element.php');
30 /**
31 * static warning
33 * overrides {@link HTML_QuickForm_static} to display staic warning.
35 * @package core_form
36 * @category form
37 * @copyright 2008 Jamie Pratt <me@jamiep.org>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class MoodleQuickForm_warning extends HTML_QuickForm_static implements templatable {
41 use templatable_form_element {
42 export_for_template as export_for_template_base;
45 /** @var string Form element type */
46 var $_elementTemplateType='warning';
48 /** @var string html for help button, if empty then no help */
49 var $_helpbutton='';
51 /** @var string class assigned to field, default is notifyproblem */
52 var $_class='';
54 /**
55 * constructor
57 * @param string $elementName (optional) name of the field
58 * @param string $elementClass (optional) show as warning or notification => 'notifyproblem'
59 * @param string $text (optional) Text to put in warning field
61 public function __construct($elementName=null, $elementClass='notifyproblem', $text=null) {
62 parent::__construct($elementName, null, $text);
63 $this->_type = 'warning';
64 if (is_null($elementClass)) {
65 $elementClass = 'notifyproblem';
67 $this->_class = $elementClass;
70 /**
71 * Old syntax of class constructor. Deprecated in PHP7.
73 * @deprecated since Moodle 3.1
75 public function MoodleQuickForm_warning($elementName=null, $elementClass='notifyproblem', $text=null) {
76 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
77 self::__construct($elementName, $elementClass, $text);
80 /**
81 * Returns HTML for this form element.
83 * @return string
85 function toHtml() {
86 global $OUTPUT;
87 return $OUTPUT->notification($this->_text, $this->_class);
90 /**
91 * get html for help button
93 * @return string html for help button
95 function getHelpButton(){
96 return $this->_helpbutton;
99 /**
100 * Gets the type of form element
102 * @return string
104 function getElementTemplateType(){
105 return $this->_elementTemplateType;
108 public function export_for_template(renderer_base $output) {
109 $context = $this->export_for_template_base($output);
110 $context['html'] = $this->toHtml();
111 return $context;