-
Notifications
You must be signed in to change notification settings - Fork 3
/
widget.php
97 lines (80 loc) · 2.06 KB
/
widget.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
<?php
/**
* @package midgardmvc_helper_forms
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
abstract class midgardmvc_helper_forms_widget
{
protected $field;
protected $label = '';
protected $placeholder = '';
protected $title = '';
protected $css = '';
public function __construct(midgardmvc_helper_forms_field $field)
{
$this->field = $field;
}
public abstract function __toString();
public function get_label()
{
return $this->label;
}
public function set_label($label)
{
$this->label = $label;
}
public function set_placeholder($placeholder)
{
$this->placeholder = $placeholder;
}
/**
* Sets the title attribute of the widget
*/
public function set_title($title)
{
$this->title = $title;
}
/**
* Sets the CSS class attribute of the widget
*/
public function set_css($css)
{
$this->css = $css;
}
public function add_label($form_field)
{
if (!$this->label)
{
return $form_field;
}
return "<label>{$this->label}{$form_field}</label>";
}
public function get_attributes()
{
$attributes = array();
if ($this->field->required)
{
$attributes[] = 'required=\'required\'';
}
if ($this->field->readonly)
{
$attributes[] = 'readonly=\'readonly\'';
}
if ($this->placeholder)
{
$attributes[] = "placeholder='" . str_replace("'", '’', $this->placeholder) . "'";
}
if ($this->title)
{
$attributes[] = "title='" . str_replace("'", '’', $this->title) . "'";
}
if ($this->css)
{
$attributes[] = "class='" . str_replace("'", '’', $this->css) . "'";
}
return implode(' ', $attributes);
}
}
?>