Completed
Push — master ( 9de830...b49918 )
by Jean-Christophe
03:44
created

HtmlFormField::setLabel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\collections\form;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
7
class HtmlFormField extends HtmlSemDoubleElement {
8
	public function __construct($identifier, $field,$label=NULL) {
9
		parent::__construct($identifier, "div","ui field");
10
		$this->content=array();
11
		if(isset($label))
12
			$this->setLabel($label);
13
		$this->setField($field);
14
	}
15
16
	public function setLabel($label){
17
		$labelO=$label;
18
		if(\is_string($label)){
19
			$labelO=new HtmlSemDoubleElement("","label");
20
			$labelO->setContent($label);
21
			$labelO->setProperty("for", \str_replace("field-", "",$this->identifier));
22
		}
23
		$this->content["label"]=$labelO;
24
	}
25
26
	public function setField($field){
27
		$this->content["field"]=$field;
28
	}
29
30
	public function getLabel(){
31
		if(\array_key_exists("label", $this->content))
32
			return $this->content["label"];
33
	}
34
35
	public function getField(){
36
		return $this->content["field"];
37
	}
38
39
	public function swapLabel(){
40
		$label=$this->getLabel();
41
		unset($this->content["label"]);
42
		$this->content["label"]=$label;
43
	}
44
}