MDL-55417 forms: Change iscancel property to issecondary for submit buttons
[moodle.git] / lib / form / submit.php
CommitLineData
a23f0aaf 1<?php
6c1fd304
RT
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 * submit type form element
20 *
21 * Contains HTML class for a submit type element
22 *
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
26 */
27
a23f0aaf 28require_once("HTML/QuickForm/submit.php");
344321e1 29require_once('templatable_form_element.php');
a23f0aaf 30
31/**
6c1fd304
RT
32 * submit type form element
33 *
a23f0aaf 34 * HTML class for a submit type element
35 *
6c1fd304
RT
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
a23f0aaf 40 */
91bda4cd 41class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatable {
344321e1
DW
42 use templatable_form_element {
43 export_for_template as export_for_template_base;
44 }
45
6c1fd304
RT
46 /**
47 * constructor
48 *
49 * @param string $elementName (optional) name of the field
50 * @param string $value (optional) field label
51 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
52 */
1a0df553
MG
53 public function __construct($elementName=null, $value=null, $attributes=null) {
54 parent::__construct($elementName, $value, $attributes);
55 }
56
57 /**
58 * Old syntax of class constructor. Deprecated in PHP7.
59 *
60 * @deprecated since Moodle 3.1
61 */
62 public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null) {
63 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
64 self::__construct($elementName, $value, $attributes);
3e8b394e 65 }
6c1fd304 66
a23f0aaf 67 /**
68 * Called by HTML_QuickForm whenever form event is made on this element
69 *
6c1fd304
RT
70 * @param string $event Name of event
71 * @param mixed $arg event arguments
72 * @param object $caller calling object
a23f0aaf 73 */
74 function onQuickFormEvent($event, $arg, &$caller)
75 {
76 switch ($event) {
77 case 'createElement':
78 parent::onQuickFormEvent($event, $arg, $caller);
79 if ($caller->isNoSubmitButton($arg[0])){
80 //need this to bypass client validation
81 //for buttons that submit but do not process the
82 //whole form.
83 $onClick = $this->getAttribute('onclick');
84 $skip = 'skipClientValidation = true;';
85 $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
86 $this->updateAttributes(array('onclick'=>$onClick));
87 }
88 return true;
89 break;
90 }
91 return parent::onQuickFormEvent($event, $arg, $caller);
92
6c1fd304
RT
93 }
94
64360ee7 95 /**
96 * Slightly different container template when frozen. Don't want to display a submit
97 * button if the form is frozen.
98 *
99 * @return string
100 */
101 function getElementTemplateType(){
102 if ($this->_flagFrozen){
103 return 'nodisplay';
104 } else {
95114b18 105 return 'actionbuttons';
64360ee7 106 }
107 }
4a0e2e63 108
6c1fd304
RT
109 /**
110 * Freeze the element so that only its value is returned
111 */
64360ee7 112 function freeze(){
113 $this->_flagFrozen = true;
114 }
4a0e2e63 115
91bda4cd 116 public function export_for_template(renderer_base $output) {
344321e1 117 $context = $this->export_for_template_base($output);
91bda4cd 118 if ($this->getName() == 'cancel') {
ce18fb1e 119 $context['secondary'] = true;
91bda4cd
DW
120 }
121 return $context;
122 }
a23f0aaf 123}