MDL-60061 mod_scorm: add support for drag/drop events
[moodle.git] / lib / form / submit.php
blobe40f457567c1b74d399402209d788f223009167f
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 * submit type form element
21 * Contains HTML class for a submit type element
23 * @package core_form
24 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once("HTML/QuickForm/submit.php");
29 require_once('templatable_form_element.php');
31 /**
32 * submit type form element
34 * HTML class for a submit type element
36 * @package core_form
37 * @category form
38 * @copyright 2006 Jamie Pratt <me@jamiep.org>
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatable {
42 use templatable_form_element {
43 export_for_template as export_for_template_base;
46 /**
47 * @var bool $primary Is this button a primary button?
49 protected $primary;
51 /**
52 * constructor
54 * @param string $elementName (optional) name of the field
55 * @param string $value (optional) field label
56 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
57 * @param bool|null $primary Is this button a primary button?
59 public function __construct($elementName=null, $value=null, $attributes=null, $primary = null) {
60 parent::__construct($elementName, $value, $attributes);
62 // Fallback to legacy behaviour if no value specified.
63 if (is_null($primary)) {
64 $this->primary = $this->getName() != 'cancel';
65 } else {
66 $this->primary = $primary;
70 /**
71 * Old syntax of class constructor. Deprecated in PHP7.
73 * @deprecated since Moodle 3.1
75 public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null, $primary = null) {
76 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
77 self::__construct($elementName, $value, $attributes, $primary);
80 /**
81 * Called by HTML_QuickForm whenever form event is made on this element
83 * @param string $event Name of event
84 * @param mixed $arg event arguments
85 * @param object $caller calling object
87 function onQuickFormEvent($event, $arg, &$caller)
89 switch ($event) {
90 case 'createElement':
91 parent::onQuickFormEvent($event, $arg, $caller);
92 if ($caller->isNoSubmitButton($arg[0])){
93 //need this to bypass client validation
94 //for buttons that submit but do not process the
95 //whole form.
96 $onClick = $this->getAttribute('onclick');
97 $skip = 'skipClientValidation = true;';
98 $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
99 $this->updateAttributes(array('onclick'=>$onClick));
101 return true;
102 break;
104 return parent::onQuickFormEvent($event, $arg, $caller);
109 * Slightly different container template when frozen. Don't want to display a submit
110 * button if the form is frozen.
112 * @return string
114 function getElementTemplateType(){
115 if ($this->_flagFrozen){
116 return 'nodisplay';
117 } else {
118 return 'actionbuttons';
123 * Freeze the element so that only its value is returned
125 function freeze(){
126 $this->_flagFrozen = true;
129 public function export_for_template(renderer_base $output) {
130 $context = $this->export_for_template_base($output);
131 if (!$this->primary) {
132 $context['secondary'] = true;
134 return $context;