当前位置: 首页>>代码示例>>PHP>>正文


PHP ElementInterface::getLabelAttributes方法代码示例

本文整理汇总了PHP中Zend\Form\ElementInterface::getLabelAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getLabelAttributes方法的具体用法?PHP ElementInterface::getLabelAttributes怎么用?PHP ElementInterface::getLabelAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Form\ElementInterface的用法示例。


在下文中一共展示了ElementInterface::getLabelAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:36,代码来源:FormLabelTwb.php

示例2: openTag

 /**
  * Generate an opening label tag
  * @param  null|array|ElementInterface $attributesOrElement
  * @return string
  */
 public function openTag($attributesOrElement = null)
 {
     $labelAttributes = array();
     if ($attributesOrElement instanceof LabelOptionsAwareInterface) {
         $labelAttributes = $attributesOrElement->getLabelAttributes();
     }
     $labelAttributes['class'] = 'btn' . (empty($labelAttributes['class']) ? '' : ' ' . $labelAttributes['class']);
     return parent::openTag($labelAttributes);
 }
开发者ID:athemcms,项目名称:netis,代码行数:14,代码来源:FormButton.php

示例3: renderLabel

 /**
  * @param ElementInterface $element
  *
  * @return string
  */
 protected function renderLabel(ElementInterface $element)
 {
     $labelPlugin = $this->getView()->plugin('sxb_form_control_label');
     $label = $element->getLabel();
     if (null !== $label) {
         $label = $labelPlugin($label, $element->getName(), $element->getLabelAttributes());
     }
     return $label;
 }
开发者ID:spoonx,项目名称:sxbootstrap,代码行数:14,代码来源:Row.php

示例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);
 }
开发者ID:abouttheweb,项目名称:zf2-twb-bundle,代码行数:18,代码来源:TwbBundleFormMultiCheckbox.php

示例5: render

 /**
  * @see \Zend\Form\View\Helper\FormCheckbox::render()
  * @param \Zend\Form\ElementInterface $oElement
  * @throws \LogicException
  * @throws \InvalidArgumentException
  * @return string
  */
 public function render(\Zend\Form\ElementInterface $oElement)
 {
     if (!$oElement instanceof \Zend\Form\Element\Checkbox) {
         throw new \InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
     }
     if (($sName = $oElement->getName()) !== 0 && empty($sName)) {
         throw new \LogicException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $aAttributes = $oElement->getAttributes();
     $aAttributes['name'] = $sName;
     $aAttributes['type'] = $this->getInputType();
     $aAttributes['value'] = $oElement->getCheckedValue();
     $sClosingBracket = $this->getInlineClosingBracket();
     if ($oElement->isChecked()) {
         $aAttributes['checked'] = 'checked';
     }
     //Render label
     $sLabelOpen = $sLabelClose = $sLabelContent = '';
     //Render label and visible element
     if ($sLabelContent = $oElement->getLabel()) {
         if ($oTranslator = $this->getTranslator()) {
             $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain());
         }
         $oLabelHelper = $this->getLabelHelper();
         $sLabelOpen = $oLabelHelper->openTag($oElement->getLabelAttributes() ?: null);
         $sLabelClose = $oLabelHelper->closeTag();
     }
     //Render checkbox
     $sElementContent = sprintf('<input %s%s', $this->createAttributesString($aAttributes), $sClosingBracket);
     //Add label markup
     if ($this->getLabelPosition($oElement) === \Zend\Form\View\Helper\FormRow::LABEL_PREPEND) {
         $sElementContent = $sLabelOpen . ($sLabelContent ? rtrim($sLabelContent) . ' ' : '') . $sElementContent . $sLabelClose;
     } else {
         $sElementContent = $sLabelOpen . $sElementContent . ($sLabelContent ? ' ' . ltrim($sLabelContent) : '') . $sLabelClose;
     }
     //Render hidden input
     if ($oElement->useHiddenElement()) {
         $sElementContent = sprintf('<input type="hidden" %s%s', $this->createAttributesString(array('name' => $aAttributes['name'], 'value' => $oElement->getUncheckedValue())), $sClosingBracket) . $sElementContent;
     }
     return $sElementContent;
 }
开发者ID:eltonoliveira,项目名称:components_bootstrap,代码行数:48,代码来源:TwbBundleFormCheckbox.php

示例6: render

 /**
  * render
  *
  * Return the HTML representation of the form element's label.
  *
  * @param ElementInterface  $element  The form element which label should be rendered.
  * @param array             $options  Optional view helper options.
  *
  * @return string
  */
 public function render(ElementInterface $element, array $options = [])
 {
     if (!empty($options)) {
         $this->setOptions($options);
     }
     $name = $element->getName();
     $label = $element->getLabel();
     if (empty($label) && false == $this->getOption('allow_empty_label', false)) {
         return '';
     }
     // Merge the label attributes
     $attributes = $this->getAttributes();
     if ($element instanceof LabelAwareInterface) {
         $attributes = array_merge($attributes, $element->getLabelAttributes());
     }
     if (!empty($name) && !isset($attributes['for'])) {
         $attributes['for'] = $name;
     }
     $this->setAttributes(array_unique($attributes));
     return parent::render($label);
 }
开发者ID:alex-patterson-webdev,项目名称:arp-form,代码行数:31,代码来源:FormLabel.php

示例7: render

 /**
  * Utility form helper that renders a label (if it exists), an element and errors
  *
  * @param ElementInterface $element
  * @return string
  * @throws \Zend\Form\Exception\DomainException
  */
 public function render(ElementInterface $element, $ignoreViewPartial = false)
 {
     $labelAttributes = $element->getLabelAttributes();
     $labelWidth = $element->getOption('labelWidth');
     if (!$labelWidth) {
         $labelWidth = $this->labelSpanWidth;
     }
     if ($element instanceof ViewPartialProviderInterface && !$ignoreViewPartial) {
         return $this->getView()->partial($element->getViewPartial(), array('element' => $element, 'labelWitdh' => $labelWidth, 'label_attributes' => $labelAttributes));
     }
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     $inputErrorClass = $this->getInputErrorClass();
     $elementErrors = $elementErrorsHelper->render($element);
     // general Class
     $form_row_class = 'row';
     if ($this->layout == Form::LAYOUT_HORIZONTAL) {
         $form_row_class = 'form-group';
     }
     // Does this element have errors ?
     if (!empty($elementErrors) && !empty($inputErrorClass) && $this->layout != Form::LAYOUT_BARE) {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . $inputErrorClass;
         $element->setAttribute('class', $classAttributes);
     }
     if (!$element->hasAttribute('id')) {
         $elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $element->getName());
         $element->setAttribute('id', $elementId);
     } else {
         $elementId = $element->getAttribute('id');
     }
     /*
      * add form-control class to all form elements, but "submit" or "reset" and Buttons!
      */
     if ($element->getAttribute('type') != 'submit' && $element->getAttribute('type') != 'reset' && $element->getAttribute('type') != 'checkbox' && !$element instanceof Button) {
         $element->setAttribute('class', $element->getAttribute('class') . ' form-control ');
     }
     $elementString = $elementHelper->render($element);
     $desc = $element->getOption('description', false);
     if ($desc && $this->layout != Form::LAYOUT_BARE) {
         if (null !== ($translator = $this->getTranslator())) {
             $desc = $translator->translate($desc, $this->getTranslatorTextDomain());
         }
         $elementString .= sprintf('<div id="%s-desc" class="cam-description alert alert-info">%s</div>', $elementId, $desc);
     }
     if (!$element instanceof \Zend\Form\Element\Hidden && !$element instanceof \Zend\Form\Element\Button && $this->layout != Form::LAYOUT_BARE) {
         $elementString .= sprintf('<div id="%s-errors" class="errors">%s</div>', $elementId, $elementErrors);
     }
     // moved label here so we can change it in the ElementViewHelper
     $label = $element->getLabel();
     if (isset($label) && '' !== $label && !$element instanceof \Zend\Form\Element\Button) {
         // Translate the label
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
         $label = $escapeHtmlHelper($label);
         $labelAttributes = $element->getLabelAttributes();
         if (empty($labelAttributes)) {
             $labelAttributes = $this->labelAttributes;
         }
         // Multicheckbox elements have to be handled differently as the HTML standard does not allow nested
         // labels. The semantic way is to group them inside a fieldset
         $type = $element->getAttribute('type');
         if ($type === 'multi_checkbox' || $type === 'radio') {
             $markup = sprintf('<fieldset><legend>%s</legend>%s</fieldset>', $label, $elementString);
         } else {
             if ($this->layout == Form::LAYOUT_BARE) {
                 $markup = $elementString;
             } else {
                 if (!isset($labelAttributes['for'])) {
                     $labelAttributes['for'] = $elementId;
                 }
                 if (Form::LAYOUT_HORIZONTAL == $this->layout) {
                     if (!isset($labelAttributes['class'])) {
                         $labelAttributes['class'] = '';
                     }
                     $labelAttributes['class'] .= ' control-label';
                 }
                 $element->setLabelAttributes($labelAttributes);
                 $label = $labelHelper($element);
                 if ($this->shouldWrap) {
                     $spanWidth = 12 - $labelWidth;
                     $elementString = sprintf('<div class="col-md-%d%s" id="' . $elementId . '-span">%s</div>', $spanWidth, $elementErrors ? " {$inputErrorClass}" : '', $elementString);
                     $label = sprintf('<div class="col-md-%d yk-label">%s</div>', $labelWidth, $label);
                 }
                 $markup = $label . $elementString;
             }
         }
     } else {
         if ($this->shouldWrap && !$element instanceof \Zend\Form\Element\Hidden && !$element instanceof \Zend\Form\Element\Button && $this->layout != Form::LAYOUT_BARE) {
             $elementString = sprintf('<div class="col-md-12">%s</div>', $elementString);
//.........这里部分代码省略.........
开发者ID:webpants,项目名称:YAWIK,代码行数:101,代码来源:FormRow.php

示例8: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\InvalidArgumentException
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof CheckboxElement) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type' . ' Zend\\Form\\Element\\Checkbox', __METHOD__));
     }
     $name = $element->getName();
     if (empty($name) && $name !== 0) {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name;' . ' none discovered', __METHOD__));
     }
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['type'] = $this->getInputType();
     $attributes['value'] = $element->getCheckedValue();
     $closingBracket = $this->getInlineClosingBracket();
     if ($element->isChecked()) {
         $attributes['checked'] = 'checked';
     }
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $labelClose = $labelHelper->closeTag();
     $labelPosition = $this->getLabelPosition();
     $globalLabelAttributes = $element->getLabelAttributes();
     if (empty($globalLabelAttributes)) {
         $globalLabelAttributes = $this->labelAttributes;
     }
     $label = $element->getAttribute('description') ?: $element->getLabel();
     $labelAttributes = $this->labelAttributes ?: $element->getLabelAttributes();
     if (null !== ($translator = $this->getTranslator())) {
         $label = $translator->translate($label, $this->getTranslatorTextDomain());
     }
     $label = $escapeHtmlHelper($label);
     $labelOpen = $labelHelper->openTag($labelAttributes);
     $template = $labelOpen . '%s%s' . $labelClose;
     switch ($labelPosition) {
         case static::LABEL_PREPEND:
             $rendered = sprintf($template, $label, $input);
             break;
         case static::LABEL_APPEND:
         default:
             $rendered = sprintf($template, $input, $label);
             break;
     }
     // Render hidden element
     $useHiddenElement = null !== $this->useHiddenElement ? $this->useHiddenElement : (method_exists($element, 'useHiddenElement') ? $element->useHiddenElement() : false);
     if ($useHiddenElement) {
         $hiddenAttributes = array('name' => $attributes['name'], 'value' => $element->getUncheckedValue());
         $rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
     }
     return $rendered;
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:59,代码来源:FormCheckbox.php

示例9: renderOptions

 /**
  * Render options
  *
  * @param ElementInterface $element
  * @param array            $options
  * @param array            $selectedOptions
  * @param array            $attributes
  * @return string
  */
 protected function renderOptions(ElementInterface $element, array $options, array $selectedOptions, array $attributes)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $labelClose = $labelHelper->closeTag();
     $labelPosition = $this->getLabelPosition();
     $globalLabelAttributes = $element->getLabelAttributes();
     $closingBracket = $this->getInlineClosingBracket();
     if (empty($globalLabelAttributes)) {
         $globalLabelAttributes = $this->labelAttributes;
     }
     $combinedMarkup = array();
     $count = 0;
     foreach ($options as $key => $optionSpec) {
         $count++;
         if ($count > 1 && array_key_exists('id', $attributes)) {
             unset($attributes['id']);
         }
         $value = '';
         $label = $key;
         $selected = false;
         $disabled = false;
         $inputAttributes = $attributes;
         $labelAttributes = $globalLabelAttributes;
         if (is_string($optionSpec) || is_numeric($optionSpec) || is_bool($optionSpec)) {
             $optionSpec = array('value' => (string) $optionSpec);
         }
         if (isset($optionSpec['value'])) {
             $value = $optionSpec['value'];
         }
         if (isset($optionSpec['label'])) {
             $label = $optionSpec['label'];
         }
         if (isset($optionSpec['selected'])) {
             $selected = $optionSpec['selected'];
         }
         if (isset($optionSpec['disabled'])) {
             $disabled = $optionSpec['disabled'];
         }
         if (isset($optionSpec['label_attributes'])) {
             $labelAttributes = isset($labelAttributes) ? array_merge($labelAttributes, $optionSpec['label_attributes']) : $optionSpec['label_attributes'];
         }
         if (isset($optionSpec['attributes'])) {
             $inputAttributes = array_merge($inputAttributes, $optionSpec['attributes']);
         }
         if (in_array($value, $selectedOptions, true)) {
             $selected = true;
         }
         $inputAttributes['value'] = $value;
         $inputAttributes['checked'] = $selected;
         $inputAttributes['disabled'] = $disabled;
         $input = sprintf('<input %s%s', $this->createAttributesString($inputAttributes), $closingBracket);
         $label = $escapeHtmlHelper($label);
         $labelOpen = $labelHelper->openTag($labelAttributes);
         $template = $labelOpen . '%s%s' . $labelClose;
         switch ($labelPosition) {
             case self::LABEL_PREPEND:
                 $markup = sprintf($template, $label, $input);
                 break;
             case self::LABEL_APPEND:
             default:
                 $markup = sprintf($template, $input, $label);
                 break;
         }
         $combinedMarkup[] = $markup;
     }
     return implode($this->getSeparator(), $combinedMarkup);
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:77,代码来源:FormMultiCheckbox.php

示例10: getLabelAttributesByElement

 /**
  * @param ElementInterface $element
  * @return array
  */
 protected function getLabelAttributesByElement($element)
 {
     $labelAttributes = $element->getLabelAttributes();
     if (empty($labelAttributes)) {
         $labelAttributes = array();
     }
     if (!isset($labelAttributes['for'])) {
         $labelAttributes['for'] = $element->getAttribute('id');
     }
     if (isset($labelAttributes['class'])) {
         $labelAttributes['class'] .= ' ';
     } else {
         $labelAttributes['class'] = '';
     }
     if (!isset($labelAttributes['size'])) {
         $size = $element->getOption('size') ? 2 : 0;
     } else {
         $size = $labelAttributes['size'];
         unset($labelAttributes['size']);
     }
     $labelAttributes['class'] .= 'control-label';
     if (!empty($size)) {
         $labelAttributes['class'] .= sprintf(' col-lg-%s col-md-%s col-sm-%s col-xs-%s', $size, $size, $size, $size);
     }
     return $labelAttributes;
 }
开发者ID:skpd,项目名称:bootstrap,代码行数:30,代码来源:FormRow.php


注:本文中的Zend\Form\ElementInterface::getLabelAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。