forked from midgardproject/midgardmvc_helper_forms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwidget.php
More file actions
58 lines (48 loc) · 1.31 KB
/
Copy pathwidget.php
File metadata and controls
58 lines (48 loc) · 1.31 KB
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
<?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 = '';
public function __construct(midgardmvc_helper_forms_field $field)
{
$this->field = $field;
}
public abstract function __toString();
public function set_label($label)
{
$this->label = $label;
}
public function set_placeholder($placeholder)
{
$this->placeholder = $placeholder;
}
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->placeholder)
{
$attributes[] = "placeholder='{$this->placeholder}'";
}
return implode(' ', $attributes);
}
}
?>