Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.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   * Textarea profile field define.
  19   *
  20   * @package   profilefield_textarea
  21   * @copyright  2007 onwards Shane Elliot {@link http://pukunui.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Class profile_field_textarea.
  27   *
  28   * @copyright  2007 onwards Shane Elliot {@link http://pukunui.com}
  29   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class profile_field_textarea extends profile_field_base {
  32  
  33      /**
  34       * Adds elements for this field type to the edit form.
  35       * @param moodleform $mform
  36       */
  37      public function edit_field_add($mform) {
  38          // Create the form field.
  39          $mform->addElement('editor', $this->inputname, format_string($this->field->name), null, null);
  40          $mform->setType($this->inputname, PARAM_RAW); // We MUST clean this before display!
  41      }
  42  
  43      /**
  44       * Overwrite base class method, data in this field type is potentially too large to be included in the user object.
  45       * @return bool
  46       */
  47      public function is_user_object_data() {
  48          return false;
  49      }
  50  
  51      /**
  52       * Process incoming data for the field.
  53       * @param stdClass $data
  54       * @param stdClass $datarecord
  55       * @return mixed|stdClass
  56       */
  57      public function edit_save_data_preprocess($data, $datarecord) {
  58          if (is_array($data)) {
  59              $datarecord->dataformat = $data['format'];
  60              $data = $data['text'];
  61          }
  62          return $data;
  63      }
  64  
  65      /**
  66       * Load user data for this profile field, ready for editing.
  67       * @param stdClass $user
  68       */
  69      public function edit_load_user_data($user) {
  70          if ($this->data !== null) {
  71              $this->data = clean_text($this->data, $this->dataformat);
  72              $user->{$this->inputname} = array('text' => $this->data, 'format' => $this->dataformat);
  73          }
  74      }
  75  
  76      /**
  77       * Display the data for this field
  78       * @return string
  79       */
  80      public function display_data() {
  81          return format_text($this->data, $this->dataformat, array('overflowdiv' => true));
  82      }
  83  
  84      /**
  85       * Return the field type and null properties.
  86       * This will be used for validating the data submitted by a user.
  87       *
  88       * @return array the param type and null property
  89       * @since Moodle 3.2
  90       */
  91      public function get_field_properties() {
  92          return array(PARAM_RAW, NULL_NOT_ALLOWED);
  93      }
  94  }
  95  
  96