/** Подготовка атрибутов */ protected function prepareAttr($attr, $add_placeholder = false) { if (is_null($attr)) { $attr = $this->getAttr(); } $arr = array('id' => $this->getInputId()); if ($add_placeholder && ($ph = $this->getPlaceholder())) { $arr['placeholder'] = $ph; } return array_merge($arr, Tag::MergeAttr($attr) ?: array()); }
/** Создание тега для вложенных опций */ protected function renderOptionsTmpl(Tag $tag) { return sprintf($this->getOptionsTmpl(), $tag->toHTML(), $tag instanceof Checkbox ? $tag->getDisplayValue() : $tag->getValue()); }
function testMergeAttr() { $res = Tag::MergeAttr('one', 'two'); $exp = array('class' => 'one two'); $this->assertEquals($exp, $res, 'Вариант 1'); $res = Tag::MergeAttr('one', array('id' => 'two')); $exp = array('class' => 'one', 'id' => 'two'); $this->assertEquals($exp, $res, 'Вариант 2'); $res = Tag::MergeAttr(array('style' => 'border: red;'), array('class' => 'red', 'style' => 'color: green;')); $exp = array('style' => 'border: red; color: green;', 'class' => 'red'); $this->assertEquals($exp, $res, 'Вариант 3'); $res = Tag::MergeAttr(array('style' => array('width' => '15px;', 'height' => '200px')), 'red'); $exp = array('style' => 'width: 15px; height: 200px;', 'class' => 'red'); $this->assertEquals($exp, $res, 'Вариант 4'); }