forked from contao/contao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormSubmit.php
140 lines (124 loc) · 2.72 KB
/
FormSubmit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao;
/**
* Class FormSubmit
*
* @property string $name
* @property string $label
* @property string $singleSRC
* @property boolean $imageSubmit
* @property boolean $required
* @property boolean $mandatory
* @property integer $minlength
* @property integer $maxlength
* @property string $src
*/
class FormSubmit extends Widget
{
/**
* Template
*
* @var string
*/
protected $strTemplate = 'form_submit';
/**
* The CSS class prefix
*
* @var string
*/
protected $strPrefix = 'widget widget-submit';
/**
* Add specific attributes
*
* @param string $strKey The attribute name
* @param mixed $varValue The attribute value
*/
public function __set($strKey, $varValue)
{
switch ($strKey)
{
case 'singleSRC':
$this->arrConfiguration['singleSRC'] = $varValue;
break;
case 'imageSubmit':
$this->arrConfiguration['imageSubmit'] = $varValue ? true : false;
break;
case 'name':
$this->arrAttributes['name'] = $varValue;
break;
case 'label':
$this->slabel = $varValue;
break;
case 'required':
case 'mandatory':
case 'minlength':
case 'maxlength':
// Ignore
break;
default:
parent::__set($strKey, $varValue);
break;
}
}
/**
* Do not validate
*/
public function validate()
{
}
/**
* Parse the template file and return it as string
*
* @param array $arrAttributes An optional attributes array
*
* @return string The template markup
*/
public function parse($arrAttributes=null)
{
if ($this->imageSubmit && $this->singleSRC)
{
$objModel = FilesModel::findByUuid($this->singleSRC);
if ($objModel !== null && is_file(System::getContainer()->getParameter('kernel.project_dir') . '/' . $objModel->path))
{
$this->src = System::getContainer()->get('contao.assets.files_context')->getStaticUrl() . $objModel->path;
}
}
return parent::parse($arrAttributes);
}
/**
* Generate the widget and return it as string
*
* @return string The widget markup
*/
public function generate()
{
if ($this->src)
{
return sprintf(
'<input type="image" src="%s" id="ctrl_%s" class="submit%s" title="%s" alt="%s"%s%s',
$this->src,
$this->strId,
($this->strClass ? ' ' . $this->strClass : ''),
StringUtil::specialchars($this->slabel),
StringUtil::specialchars($this->slabel),
$this->getAttributes(),
$this->strTagEnding
);
}
// Return the regular button
return sprintf(
'<button type="submit" id="ctrl_%s" class="submit%s"%s>%s</button>',
$this->strId,
($this->strClass ? ' ' . $this->strClass : ''),
$this->getAttributes(),
$this->slabel
);
}
}