本文整理汇总了PHP中Zend\Form\ElementInterface::setValueOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::setValueOptions方法的具体用法?PHP ElementInterface::setValueOptions怎么用?PHP ElementInterface::setValueOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::setValueOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareLabel
protected function prepareLabel(ElementInterface $element)
{
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$valuesOptions = $element->getValueOptions();
//append span with c-indicator for each option
foreach ($valuesOptions as $key => $optionSpec) {
if (is_scalar($optionSpec)) {
$optionSpec = ['label' => $optionSpec, 'value' => $key];
}
if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
$optionSpec['label'] = $escapeHtmlHelper($optionSpec['label']);
}
$optionSpec['label'] = '<span class="c-indicator"></span>' . $optionSpec['label'];
$valuesOptions[$key] = $optionSpec;
}
//disable escape because it was already used above
$element->setLabelOption('disable_html_escape', true);
$element->setValueOptions($valuesOptions);
}
示例2: render
public function render(ElementInterface $element)
{
$type = $element->getAttribute('type');
if ($type == 'multi_checkbox' || $type == "radio") {
$aOptions = $element->getValueOptions();
$aAtributes = $element->getOptions();
$aClasse = $element->getAttributes();
$aClasse = explode(" ", @$aClasse["class"]);
$sType = $type;
$selected = $element->getValue();
$disabled = $element->getAttribute("disabled");
foreach ($aOptions as $sKey => $aOption) {
if (is_scalar($aOption)) {
$aOption = array('label' => " " . $aOption, 'value' => $sKey);
}
$aOption['label_attributes'] = array();
$classe = "";
if (!in_array("not-bootstrap", $aClasse)) {
$classe = "btn btn-default ";
if ($type == "multi_checkbox") {
if (@in_array($sKey, $selected)) {
$classe .= "active";
}
} else {
if ($type == "radio") {
if ($sKey == $selected) {
$classe .= "active";
}
}
}
}
if (in_array("not-bootstrap", $aClasse)) {
$classe .= "not-bootstrap";
}
if ($disabled) {
$classe .= " disabled";
}
if (empty($aOption['label_attributes']['class'])) {
$aOption['label_attributes']['class'] = trim($classe);
} elseif (!preg_match('/(\\s|^)' . preg_quote($classe) . '(\\s|$)/', $aOption['label_attributes']['class'])) {
$aOption['label_attributes']['class'] .= trim(' ' . $classe);
}
if (isset($aAtributes['data'])) {
foreach ($aAtributes['data'] as $key => $value) {
$aOption['label_attributes']['data-' . $key] = $value[$sKey];
}
}
if ($disabled) {
if ($type == "multi_checkbox") {
if (@in_array($sKey, $selected)) {
$aOptions[$sKey] = $aOption;
} else {
unset($aOptions[$sKey]);
}
} else {
if ($type == "radio") {
if ($sKey == $selected) {
$aOptions[$sKey] = $aOption;
} else {
unset($aOptions[$sKey]);
}
}
}
} else {
$aOptions[$sKey] = $aOption;
}
}
$element->setValueOptions($aOptions);
if (!in_array("not-bootstrap", $aClasse)) {
return sprintf('<div><div class="btn-group" data-toggle="buttons">%s</div></div>', parent::render($element));
} else {
return sprintf('<div>%s</div>', parent::render($element));
}
}
return parent::render($element);
}