Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * Form for editing steps.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_usertours\local\forms;
  26  
  27  defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
  28  
  29  require_once($CFG->libdir . '/formslib.php');
  30  
  31  /**
  32   * Form for editing steps.
  33   *
  34   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class editstep extends \moodleform {
  38      /**
  39       * @var tool_usertours\step $step
  40       */
  41      protected $step;
  42  
  43      /**
  44       * Create the edit step form.
  45       *
  46       * @param   string      $target     The target of the form.
  47       * @param   step        $step       The step being editted.
  48       */
  49      public function __construct($target, \tool_usertours\step $step) {
  50          $this->step = $step;
  51  
  52          parent::__construct($target);
  53      }
  54  
  55      /**
  56       * Form definition.
  57       */
  58      public function definition() {
  59          $mform = $this->_form;
  60  
  61          $mform->addElement('header', 'heading_target', get_string('target_heading', 'tool_usertours'));
  62          $types = [];
  63          foreach (\tool_usertours\target::get_target_types() as $value => $type) {
  64              $types[$value] = get_string('target_' . $type, 'tool_usertours');
  65          }
  66          $mform->addElement('select', 'targettype', get_string('targettype', 'tool_usertours'), $types);
  67          $mform->addHelpButton('targettype', 'targettype', 'tool_usertours');
  68  
  69          // The target configuration.
  70          foreach (\tool_usertours\target::get_target_types() as $value => $type) {
  71              $targetclass = \tool_usertours\target::get_classname($type);
  72              $targetclass::add_config_to_form($mform);
  73          }
  74  
  75          // Content of the step.
  76          $mform->addElement('header', 'heading_content', get_string('content_heading', 'tool_usertours'));
  77          $mform->addElement('textarea', 'title', get_string('title', 'tool_usertours'));
  78          $mform->addRule('title', get_string('required'), 'required', null, 'client');
  79          $mform->setType('title', PARAM_TEXT);
  80          $mform->addHelpButton('title', 'title', 'tool_usertours');
  81  
  82          $mform->addElement('textarea', 'content', get_string('content', 'tool_usertours'));
  83          $mform->addRule('content', get_string('required'), 'required', null, 'client');
  84          $mform->setType('content', PARAM_RAW);
  85          $mform->addHelpButton('content', 'content', 'tool_usertours');
  86  
  87          // Add the step configuration.
  88          $mform->addElement('header', 'heading_options', get_string('options_heading', 'tool_usertours'));
  89          // All step configuration is defined in the step.
  90          $this->step->add_config_to_form($mform);
  91  
  92          // And apply any form constraints.
  93          foreach (\tool_usertours\target::get_target_types() as $value => $type) {
  94              $targetclass = \tool_usertours\target::get_classname($type);
  95              $targetclass::add_disabled_constraints_to_form($mform);
  96          }
  97  
  98          $this->add_action_buttons();
  99      }
 100  }