Skip to content

Commit 9fed17e

Browse files
committed
Simplification
1 parent 4896154 commit 9fed17e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Ajax/bootstrap/html/HtmlButtongroups.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,32 @@ public function addElement($element) {
7171
$iid=sizeof($this->elements)+1;
7272
if (($element instanceof HtmlDropdown)||($element instanceof HtmlSplitbutton)) {
7373
$this->addExistingDropDown($element);
74-
$this->elements[]=$element;
75-
} elseif ($element instanceof HtmlButton) {
76-
$this->elements[]=$element;
7774
} elseif (\is_array($element)) {
78-
if (array_key_exists("glyph", $element))
79-
$bt=new HtmlGlyphButton($this->identifier."-button-".$iid);
80-
elseif (array_key_exists("btnCaption", $element)) {
81-
if (array_key_exists("split", $element))
82-
$bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid);
83-
else
84-
$bt=new HtmlDropdown($this->identifier."-dropdown-".$iid);
85-
$this->dropdownAsButton($bt);
86-
} else
87-
$bt=new HtmlButton($this->identifier."-button-".$iid);
88-
$bt->fromArray($element);
89-
$this->elements[]=$bt;
90-
$result=$bt;
75+
$result=$this->_addArrayElement($element,$iid);
9176
} elseif (is_string($element)) {
92-
$bt=new HtmlButton($this->identifier."-button-".$iid);
93-
$bt->setValue($element);
94-
$this->elements[]=$bt;
95-
$result=$bt;
77+
$result=new HtmlButton($this->identifier."-button-".$iid,$element);
9678
}
79+
if($result instanceof HtmlButton)
80+
$this->elements[]=$result;
9781
return $result;
9882
}
9983

84+
private function _addArrayElement(array $element,int $iid){
85+
if (array_key_exists("glyph", $element))
86+
$bt=new HtmlGlyphButton($this->identifier."-button-".$iid);
87+
elseif (array_key_exists("btnCaption", $element)) {
88+
if (array_key_exists("split", $element))
89+
$bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid);
90+
else{
91+
$bt=new HtmlDropdown($this->identifier."-dropdown-".$iid);
92+
$this->dropdownAsButton($bt);
93+
}
94+
} else
95+
$bt=new HtmlButton($this->identifier."-button-".$iid);
96+
$bt->fromArray($element);
97+
return $bt;
98+
}
99+
100100
public function addElements($elements) {
101101
foreach ( $elements as $element ) {
102102
$this->addElement($element);

0 commit comments

Comments
 (0)