Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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.
  13  //
  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/>.
  16  
  17  
  18  /**
  19   * static warning element
  20   *
  21   * Contains class for static warning type element
  22   *
  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
  26   */
  27  require_once("HTML/QuickForm/static.php");
  28  require_once ('templatable_form_element.php');
  29  
  30  /**
  31   * static warning
  32   *
  33   * overrides {@link HTML_QuickForm_static} to display staic warning.
  34   *
  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
  39   */
  40  class MoodleQuickForm_warning extends HTML_QuickForm_static implements templatable {
  41      use templatable_form_element {
  42          export_for_template as export_for_template_base;
  43      }
  44  
  45      /** @var string Form element type */
  46      var $_elementTemplateType='warning';
  47  
  48      /** @var string html for help button, if empty then no help */
  49      var $_helpbutton='';
  50  
  51      /** @var string class assigned to field, default is notifyproblem */
  52      var $_class='';
  53  
  54      /**
  55       * constructor
  56       *
  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
  60       */
  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';
  66          }
  67          $this->_class = $elementClass;
  68      }
  69  
  70      /**
  71       * Old syntax of class constructor. Deprecated in PHP7.
  72       *
  73       * @deprecated since Moodle 3.1
  74       */
  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);
  78      }
  79  
  80      /**
  81       * Returns HTML for this form element.
  82       *
  83       * @return string
  84       */
  85      function toHtml() {
  86          global $OUTPUT;
  87          return $OUTPUT->notification($this->_text, $this->_class);
  88      }
  89  
  90      /**
  91       * get html for help button
  92       *
  93       * @return string html for help button
  94       */
  95      function getHelpButton(){
  96          return $this->_helpbutton;
  97      }
  98  
  99      /**
 100       * Gets the type of form element
 101       *
 102       * @return string
 103       */
 104      function getElementTemplateType(){
 105          return $this->_elementTemplateType;
 106      }
 107  
 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;
 112      }
 113  }