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


PHP ElementInterface::getLabel方法代码示例

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


在下文中一共展示了ElementInterface::getLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:quality520,项目名称:zend-framework-2-video-code,代码行数:26,代码来源:Bootstrap3FormRow.php

示例2: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @param String $buttonContent
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element, $buttonContent = null)
 {
     //$view = $this->getView();
     //$view->headScript()->appendFile($view->basePath('/Core/js/bootstrap-switch.js'));
     if (null === $buttonContent) {
         $buttonContent = $element->getLabel();
         if (null === $buttonContent) {
             throw new Exception\DomainException(sprintf('%s expects either button content as the second argument, ' . 'or that the element provided has a label value; neither found', __METHOD__));
         }
         if (null !== ($translator = $this->getTranslator())) {
             $buttonContent = $translator->translate($buttonContent, $this->getTranslatorTextDomain());
         }
         $element->setLabel('');
     }
     //$escape         = $this->getEscapeHtmlHelper();
     //$translator     = $this->getTranslator();
     //$name           = $element->getName();
     $value = $element->getValue();
     $checkedBoole = $value == 1 || $value == 'on';
     //$checked        = $checkedBoole?'checked="checked"':'';
     $checkedClass = $checkedBoole ? 'active"' : '';
     $buttonContent = '<div class="btn-group" data-toggle="buttons">' . PHP_EOL . '<span class="btn btn-default ' . $checkedClass . '">' . PHP_EOL . parent::render($element) . $buttonContent . PHP_EOL . '</span>' . PHP_EOL . '</div>' . PHP_EOL;
     //$buttonContent = '<div><div class="processing yk-hidden"><span class="fa-spin yk-icon-spinner yk-icon"></span> ' .
     //    $translator->translate('processing', $this->getTranslatorTextDomain()) . '</div><div class="default">' . $escape($buttonContent) . '</div></div>';
     return $buttonContent;
 }
开发者ID:vfulco,项目名称:YAWIK,代码行数:34,代码来源:ToggleButton.php

示例3: 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();
     $attributes['class'] = 'sr-only';
     $closingBracket = $this->getInlineClosingBracket();
     if ($element->isChecked()) {
         $attributes['checked'] = 'checked';
     }
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $label = $element->getLabel();
     $rendered = '<div class="checkbox"><label class="checkbox-custom" data-initialize="checkbox">' . $input . '<span class="checkbox-label">' . $label . '</span>' . '</label></div>';
     if ($element->useHiddenElement()) {
         $hiddenAttributes = array('name' => $attributes['name'], 'value' => $element->getUncheckedValue());
         $rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
     }
     return $rendered;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:35,代码来源:FormCheckBox.php

示例4: 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

示例5: render

 public function render(ElementInterface $element)
 {
     $req = '';
     if ($element->getOption('required')) {
         $req = 'required';
     }
     return sprintf('<tr><td>%s</td><td>%s</td>  </tr>', $element->getLabel(), parent::render($element));
 }
开发者ID:abelclopes,项目名称:ZF2-Intermediario-com-acl,代码行数:8,代码来源:FormElement.php

示例6: 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)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     $label = $element->getLabel();
     $inputErrorClass = $this->getInputErrorClass();
     $elementErrors = $elementErrorsHelper->render($element);
     // Does this element have errors ?
     if (!empty($elementErrors) && !empty($inputErrorClass)) {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . $inputErrorClass;
         $element->setAttribute('class', $classAttributes);
     }
     $elementString = $elementHelper->render($element);
     if (!empty($label)) {
         $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 ($element->hasAttribute('id')) {
                 $labelOpen = $labelHelper($element);
                 $labelClose = '';
                 $label = '';
             } else {
                 $labelOpen = $labelHelper->openTag($labelAttributes);
                 $labelClose = $labelHelper->closeTag();
             }
             switch ($this->labelPosition) {
                 case self::LABEL_PREPEND:
                     $markup = $labelOpen . '<span>' . $label . '</span>' . $elementString . $labelClose;
                     break;
                 case self::LABEL_APPEND:
                 default:
                     $markup = $labelOpen . $elementString . '<span>' . $label . '</span>' . $labelClose;
                     break;
             }
             if ($this->renderErrors) {
                 $markup .= $elementErrors;
             }
         }
     } else {
         if ($this->renderErrors) {
             $markup = $elementString . $elementErrors;
         } else {
             $markup = $elementString;
         }
     }
     return $markup;
 }
开发者ID:nuklehed,项目名称:zf2,代码行数:65,代码来源:FormRow.php

示例7: 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

示例8: getLabelContent

 /**
  * @param ElementInterface $oElement
  * @return string
  */
 public function getLabelContent(ElementInterface $oElement)
 {
     $sLabelContent = $oElement->getLabel() ?: '';
     if ($sLabelContent) {
         if ($oTranslator = $this->getTranslator()) {
             $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain());
         }
     }
     return $sLabelContent;
 }
开发者ID:cityware,项目名称:city-bootstrap,代码行数:14,代码来源:BootstrapFormCheckbox.php

示例9: render

 public function render(ElementInterface $element, $labelPosition = null)
 {
     $result = '<div class="zui-field-group">';
     if ($element->getLabel()) {
         $result .= $this->getView()->formLabel($element);
     }
     $result .= $this->getView()->formElement($element);
     $result .= $this->getView()->zourceFormDescription($element);
     $result .= $this->getView()->formElementErrors($element);
     $result .= '</div>';
     return $result;
 }
开发者ID:zource,项目名称:zource,代码行数:12,代码来源:FormRow.php

示例10: __invoke

 public function __invoke(ElementInterface $element = null, $labelContent = null, $position = null)
 {
     $labelContent = $element->getLabel();
     // Implement all default lines of Zend\Form\View\Helper\FormLabel
     // Set $required to a default of true | existing elements required-value
     $required = $element->hasAttribute('required') ? $element->getAttribute('required') : true;
     if (true === $required && ($labelContent != '' || $labelContent != null || $labelContent != false)) {
         $labelContent = sprintf('<div class="col-lg-10"><span class="im-required">(*)</span> %s</div>', $labelContent);
     } elseif (false === $required && ($labelContent != '' || $labelContent != null || $labelContent != false)) {
         $labelContent = $labelContent;
     }
     return $labelContent;
 }
开发者ID:abelclopes,项目名称:ZF2-Intermediario-com-acl,代码行数:13,代码来源:FormLabel.php

示例11: render

 /**
  * Utility form helper that renders a label (if it exists), an element and errors
  *
  * @param  ElementInterface $element
  * @throws \Zend\Form\Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element, $labelPosition = null)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     $label = $element->getLabel();
     $inputErrorClass = $this->getInputErrorClass();
     if (isset($label) && '' !== $label) {
         // Translate the label
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
     }
     // Does this element have errors ?
     if (count($element->getMessages()) > 0 && !empty($inputErrorClass)) {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . $inputErrorClass;
         $element->setAttribute('class', $classAttributes);
     }
     if ($this->partial) {
         $vars = array('element' => $element, 'label' => $label, 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors);
         return $this->view->render($this->partial, $vars);
     }
     $rowOpen = '<div class="form-group">';
     $rowClose = '</div>';
     $elementString = $elementHelper->render($element);
     if ($elementErrorsHelper->render($element)) {
         $rowOpen = '<div class="form-group has-error">';
         $elementErrors = $elementErrorsHelper->setMessageOpenFormat('<p class="text-danger">')->setMessageSeparatorString('<br />')->setMessageCloseString('</p>')->render($element);
         $elementString .= $elementErrors;
     }
     // hidden elements do not need a <label> -https://github.com/zendframework/zf2/issues/5607
     $type = $element->getAttribute('type');
     if (isset($label) && '' !== $label && $type !== 'hidden') {
         if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
             $label = $escapeHtmlHelper($label);
         }
         if ($label !== '' && !$element->hasAttribute('id') || $element instanceof LabelAwareInterface && $element->getLabelOption('always_wrap')) {
             $label = '<label class="col-sm-3 control-label">' . $label . '</label>';
         }
         $elementString = '<div class="col-sm-9">' . $elementString . '</div>';
         // Button element is a special case, because label is always rendered inside it
         if ($element instanceof Button || $element instanceof Checkbox || $element instanceof Radio) {
             $label = '<div class="col-sm-3"></div>';
         }
         $markup = $label . $elementString;
     } else {
         $markup = $elementString;
     }
     return $rowOpen . $markup . $rowClose;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:58,代码来源:FormHorizontal.php

示例12: render

    public function render(ElementInterface $element)
    {
        $escapeHtmlHelper = $this->getEscapeHtmlHelper();
        $labelHelper = $this->getLabelHelper();
        $elementHelper = $this->getElementHelper();
        $elementErrorsHelper = $this->getElementErrorsHelper();
        $label = $element->getLabel();
        $inputErrorClass = $this->getInputErrorClass();
        $elementErrors = $elementErrorsHelper->render($element);
        // Does this element have errors ?
        if (!empty($elementErrors) && !empty($inputErrorClass)) {
            $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
            $classAttributes = $classAttributes . $inputErrorClass;
            $element->setAttribute('class', $classAttributes);
        }
        if (!$element->hasAttribute('id')) {
            $inputId = 'input' . ucfirst($element->getAttribute('name'));
            $element->setAttribute('id', $inputId);
        } else {
            $inputId = $element->getAttribute('id');
        }
        $markup = <<<EOD
<div class="control-group%extraClass">
    <label for="{$inputId}" class="control-label">%label:</label>
    <div class="controls">
        %input
        %help
    </div>
</div>
EOD;
        $elementString = $elementHelper->render($element);
        if (null !== ($translator = $this->getTranslator())) {
            $label = $translator->translate($label, $this->getTranslatorTextDomain());
        }
        $label = $escapeHtmlHelper($label);
        if (!$this->renderErrors) {
            $elementErrors = '';
            $markup = str_replace('%extraClass', '', $markup);
        }
        $markup = str_replace('%label', $label, $markup);
        $markup = str_replace('%input', $elementString, $markup);
        if ($elementErrors) {
            $elementErrors = '<span class="help-inline">' . $elementErrors . '</span>';
            $markup = str_replace('%extraClass', ' error', $markup);
        } else {
            $markup = str_replace('%extraClass', '', $markup);
        }
        $markup = str_replace('%help', $elementErrors, $markup);
        return $markup;
    }
开发者ID:caferrari,项目名称:zf2-simple-crud-module,代码行数:50,代码来源:BootstrapRow.php

示例13: render

 public function render(ElementInterface $element)
 {
     $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__));
     }
     $label = $element->getLabel();
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['type'] = $this->getInputType();
     $attributes['class'] = 'sr-only';
     $attributes['value'] = $element->getValue();
     $closingBracket = $this->getInlineClosingBracket();
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $rendered = '<div class="radio"><label class="radio-custom" data-initialize="radio">' . $input . '</label>' . $label . '</div>';
     return $rendered;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:17,代码来源:FormRadio.php

示例14: render

 /**
  * {@inheritDoc}
  *
  * @param  ElementInterface $element
  */
 public function render($content, array $attribs = [], ElementInterface $element = null)
 {
     if ($content instanceof LabelAwareInterface) {
         $content = $content->getLabel();
     } elseif ($element instanceof LabelAwareInterface) {
         $content = $element->getLabel();
     }
     if (is_string($content) && $this->hasTranslator() && $this->isTranslatorEnabled()) {
         $content = $this->getTranslator()->translate($content, $this->getTranslatorTextDomain());
     }
     if ($element instanceof FormInterface && ($object = $element->getObject()) && method_exists($object, '__toString')) {
         $content = sprintf($content, $object);
     }
     if ($element && (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape'))) {
         $escapeHtmlHelper = $this->getEscapeHtmlHelper();
         $content = $escapeHtmlHelper($content);
     }
     return parent::render($content, $attribs);
 }
开发者ID:coolms,项目名称:common,代码行数:24,代码来源:Label.php

示例15: 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)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     $label = $element->getLabel();
     $inputErrorClass = $this->getInputErrorClass();
     $elementErrors = $elementErrorsHelper->render($element);
     // Does this element have errors ?
     if (!empty($elementErrors) && !empty($inputErrorClass)) {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . $inputErrorClass;
         $element->setAttribute('class', $classAttributes);
     }
     $elementString = $elementHelper->render($element);
     $markup = $this->openTag($element);
     if (!empty($label)) {
         $label = $escapeHtmlHelper($label);
         $labelAttributes = $element->getLabelAttributes();
         $labelAttributes = is_null($labelAttributes) ? array() : $labelAttributes;
         if (array_key_exists('class', $labelAttributes) && !empty($labelAttributes['class'])) {
             $labelAttributes['class'] .= ' ';
         }
         $labelAttributes['class'] = 'control-label';
         $labelOpen = $labelHelper->openTag($labelAttributes);
         $labelClose = $labelHelper->closeTag();
         $markup .= $labelOpen . $label . $labelClose . '<div class="controls">' . $elementString;
         if ($this->renderErrors) {
             $markup .= $elementErrors;
         }
         $markup .= '</div>';
     } else {
         if ($this->renderErrors) {
             $markup .= $elementString . $elementErrors;
         } else {
             $markup .= $elementString;
         }
     }
     $markup .= $this->closeTag();
     return $markup;
 }
开发者ID:rumeau,项目名称:zf-twitter-bootstrap,代码行数:49,代码来源:FormRow.php


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