本文整理汇总了PHP中Zend\Form\ElementInterface::setLabelAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::setLabelAttributes方法的具体用法?PHP ElementInterface::setLabelAttributes怎么用?PHP ElementInterface::setLabelAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::setLabelAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Renders a form element label from an element
* @param \Zend\Form\ElementInterface $element
* @param array|null $displayOptions
* @return string
* @throws \Zend\Form\Exception\DomainException
*/
public function render(ElementInterface $element, array $displayOptions = array())
{
$labelContent = $element->getLabel();
if (empty($labelContent)) {
throw new DomainException(sprintf('%s: No label set in the element.', __METHOD__));
}
//Translate
if (null !== ($translator = $this->getTranslator())) {
$labelContent = $translator->translate($labelContent, $this->getTranslatorTextDomain());
}
//Escape
$escaperHtml = $this->getEscapeHtmlHelper();
$labelContent = $escaperHtml($labelContent);
//Label attributes
$labelAttributes = $element->getLabelAttributes();
if (empty($labelAttributes)) {
$labelAttributes = array();
}
$labelAttributes = $this->genUtil->addWordsToArrayItem('control-label', $labelAttributes, 'class');
if (array_key_exists('required', $displayOptions) && $displayOptions['required']) {
$labelAttributes = $this->genUtil->addWordsToArrayItem('required', $labelAttributes, 'class');
}
if (!array_key_exists('id', $labelAttributes)) {
$labelAttributes['id'] = 'label-' . $element->getName();
}
$element->setLabelAttributes($labelAttributes);
$formLabelHelper = $this->formLabelHelper;
return $formLabelHelper($element, $labelContent);
}
示例2: render
public function render(ElementInterface $element)
{
$eleWrapClass = ['col-sm-10'];
$label = $element->getLabel();
$labelHtml = '';
if (!empty($label)) {
// label
$element->setLabelAttributes(['class' => 'col-sm-2 control-label']);
$labelHelper = $this->getLabelHelper();
$labelHtml = $labelHelper($element);
} else {
$eleWrapClass[] = 'col-md-offset-2';
}
// element
$element->setAttribute('class', 'form-control');
$elementHelper = $this->getElementHelper();
$errorHtml = '';
$errorClass = '';
if (count($element->getMessages()) > 0) {
$errorHelper = $this->getElementErrorsHelper();
$errorHtml = $errorHelper($element);
$errorClass = 'has-error';
}
$elementHtml = sprintf($this->eleWrap, implode(' ', $eleWrapClass), $elementHelper($element), $errorHtml);
return sprintf($this->wrap, $errorClass, $labelHtml, $elementHtml);
}
示例3: render
/**
* @see FormMultiCheckbox::render()
* @param ElementInterface $oElement
* @return string
*/
public function render(ElementInterface $oElement)
{
$aElementOptions = $oElement->getOptions();
// For inline multi-checkbox
if (isset($aElementOptions['inline']) && $aElementOptions['inline'] == true) {
$this->setSeparator('');
$oElement->setLabelAttributes(array('class' => 'checkbox-inline'));
return sprintf('%s', parent::render($oElement));
}
$this->setSeparator('</div><div class="checkbox">');
$oElement->setLabelAttributes(array('class' => 'checkbox'));
return sprintf('<div class="checkbox">%s</div>', parent::render($oElement));
}
示例4: render
/**
* @see \Zend\Form\View\Helper\FormMultiCheckbox::render()
* @param \Zend\Form\ElementInterface $oElement
* @return string
*/
public function render(\Zend\Form\ElementInterface $oElement)
{
$aElementOptions = $oElement->getOptions();
$sCheckboxClass = isset($aElementOptions['inline']) && $aElementOptions['inline'] == false ? 'checkbox' : 'checkbox-inline';
$aLabelAttributes = $oElement->getLabelAttributes();
if (empty($aLabelAttributes['class'])) {
$aLabelAttributes['class'] = $sCheckboxClass;
} elseif (!preg_match('/(\\s|^)' . $sCheckboxClass . '(\\s|$)/', $aLabelAttributes['class'])) {
$aLabelAttributes['class'] .= ' ' . $sCheckboxClass;
}
$oElement->setLabelAttributes($aLabelAttributes);
return parent::render($oElement);
}
示例5: render
/**
* @see \Zend\Form\View\Helper\FormMultiCheckbox::render()
* @param \Zend\Form\ElementInterface $oElement
* @return string
*/
public function render(\Zend\Form\ElementInterface $oElement)
{
$aElementOptions = $oElement->getOptions();
// For no inline multi-checkbox
if ($bNoInline = isset($aElementOptions['inline']) && $aElementOptions['inline'] == false) {
$sCheckboxClass = 'checkbox';
$this->setSeparator('</div><div class="checkbox">');
} else {
$sCheckboxClass = 'checkbox-inline';
$this->setSeparator('');
}
$oElement->setLabelAttributes(array('class' => $sCheckboxClass));
return $bNoInline ? '<div class="checkbox">' . parent::render($oElement) . '</div>' : parent::render($oElement);
}