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


PHP ElementInterface::hasAttribute方法代码示例

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


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

示例1: closeTag

 /**
  * Return a closing label tag
  *
  * @return string
  */
 public function closeTag()
 {
     $result = '</label>';
     if ($this->element->hasAttribute('required') && $this->element->getAttribute('required')) {
         $result = sprintf('<span class="required-mark">*</span> %s', $result);
     }
     return $result;
 }
开发者ID:kokspflanze,项目名称:PServerCore,代码行数:13,代码来源:FormLabel.php

示例2: render

 /**
  * Override
  * 
  * Render the captcha
  *
  * @param  ElementInterface $element
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     //we could also set the separator here to break between the inputs and the image.
     //$this->setSeparator('')
     $captcha = $element->getCaptcha();
     if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
         throw new DomainException(sprintf('%s requires that the element has a "captcha" attribute of type Recruitment\\Model\\CaptchaImage;
     none found', __METHOD__));
     }
     $captcha->generate();
     $imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'alt' => $captcha->getImgAlt(), 'src' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(), 'class' => 'thumbnail center-block');
     if ($element->hasAttribute('id')) {
         $imgAttributes['id'] = $element->getAttribute('id') . '-image';
     }
     $closingBracket = $this->getInlineClosingBracket();
     $img = sprintf('<img  %s%s ', $this->createAttributesString($imgAttributes), $closingBracket);
     $position = $this->getCaptchaPosition();
     $separator = $this->getSeparator();
     $captchaInput = $this->renderCaptchaInputs($element);
     $pattern = '%s' . '<div class="input-group">' . '%s%s' . '<span class="input-group-btn">' . '<button id="' . $element->getAttribute('id') . '-refresh' . '" class="btn btn-default" type="button">' . '<i class="ion-loop"></i>' . '</button>' . '</span>' . '</div>';
     if ($position == self::CAPTCHA_PREPEND) {
         return sprintf($pattern, $captchaInput, $separator, $img);
     }
     return sprintf($pattern, $img, $separator, $captchaInput);
 }
开发者ID:CATSInformatica,项目名称:CatsSys,代码行数:34,代码来源:CaptchaImage.php

示例3: __invoke

 public function __invoke(ElementInterface $element = null)
 {
     if ($element && !$element->hasAttribute('class')) {
         $this->addClasses($element, ['btn', 'btn-default']);
     }
     return parent::__invoke($element);
 }
开发者ID:phower,项目名称:zf2-bootstrap3-module,代码行数:7,代码来源:FormSubmit.php

示例4: init

 public function init(ElementInterface $element)
 {
     $this->formElement = $element;
     if ($element->hasAttribute('template')) {
         $this->template = $element->getAttribute('template');
     }
 }
开发者ID:vfulco,项目名称:YAWIK,代码行数:7,代码来源:TemplateProvider.php

示例5: render

 /**
  * {@inheritDoc}
  */
 public function render(ElementInterface $element)
 {
     $captcha = $element->getCaptcha();
     if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
         throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute' . ' of type Zend\\Captcha\\Image; none found', __METHOD__));
     }
     // Generates ID, but NOT word and image
     $captcha->generate();
     // Generates URL to access image, and image won't be generated until the URL is accessed
     $imgSrc = $captcha->getImgUrl() . '?id=' . $captcha->getId();
     $imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'src' => $imgSrc, 'onclick' => sprintf('this.src=\'%s&refresh=\'+Math.random()', $imgSrc), 'style' => 'cursor: pointer; vertical-align: middle;', 'alt' => __('CAPTCHA image'), 'title' => __('Click to refresh CAPTCHA'));
     if ($element->hasAttribute('id')) {
         $imgAttributes['id'] = $element->getAttribute('id') . '-image';
     } else {
         $imgAttributes['id'] = $captcha->getId() . '-image';
     }
     $closingBracket = $this->getInlineClosingBracket();
     $img = sprintf('<img %s%s', $this->createAttributesString($imgAttributes), $closingBracket);
     $position = $this->getCaptchaPosition();
     $separator = $this->getSeparator();
     $captchaInput = $this->renderCaptchaInputs($element);
     $pattern = '%s%s%s';
     if ($position == static::CAPTCHA_PREPEND) {
         return sprintf($pattern, $captchaInput, $separator, $img);
     }
     return sprintf($pattern, $img, $separator, $captchaInput);
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:30,代码来源:Image.php

示例6: __invoke

 public function __invoke(ElementInterface $element = null)
 {
     if ($element && !$element->hasAttribute('class')) {
         $this->addClass($element, 'form-control');
     }
     return parent::__invoke($element);
 }
开发者ID:phower,项目名称:zf2-bootstrap3-module,代码行数:7,代码来源:FormDateTime.php

示例7: render

 /**
  * {@inheritDoc}
  */
 public function render(ElementInterface $element)
 {
     if ($element->hasAttribute('class')) {
         $class = $element->getAttribute('class');
         if (strpos($class, 'selectpicker') !== false && $this->getView()->jQuery()->twbs->bootstrapSelect) {
             if (!$element->hasAttribute('data-width')) {
                 $element->setAttribute('data-width', 'auto');
             }
             if (strpos($class, 'btn-') === false) {
                 $class .= ' btn-default';
             }
             $element->setAttribute('data-style', $class);
             $element->setAttribute('class', 'selectpicker');
         }
     }
     return parent::render($element);
 }
开发者ID:coolms,项目名称:twbs,代码行数:20,代码来源:FormSelect.php

示例8: __invoke

 public function __invoke(ElementInterface $element = null, $labelContent = null, $position = null)
 {
     // Set $required to a default of true | existing elements required-value
     $required = $element->hasAttribute('required') ? true : false;
     if (true === $required) {
         $labelContent = sprintf('%s<span class="required-mark">*</span>', $labelContent);
     }
     return $this->openTag($element) . $labelContent . $this->closeTag();
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:9,代码来源:RequiredMarkInFormLabel.php

示例9: render

 public function render(ElementInterface $element)
 {
     if ($element->hasAttribute('data-placeholder')) {
         $placeholder = $element->getAttribute('data-placeholder');
         $placeholder = $this->getTranslator()->translate($placeholder, $this->getTranslatorTextDomain());
         $element->setAttribute('data-placeholder', $placeholder);
     }
     return parent::render($element);
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:9,代码来源:FormSelect.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

 /**
  * {@inheritDoc}
  */
 public function render($content, array $attribs = [], ElementInterface $element = null)
 {
     if ($element) {
         $srOnly = $this->getSrOnly();
         if (null === $srOnly) {
             if ($element instanceof LabelAwareInterface) {
                 if (!$element->getLabel()) {
                     return '';
                 }
                 $srOnly = $element->getLabelOption('sr_only');
             }
             if (null === $srOnly && $element->hasAttribute('placeholder')) {
                 $srOnly = true;
             }
         }
         if ($srOnly) {
             $attribs = array_merge_recursive($attribs, ['class' => 'sr-only']);
         }
     }
     return parent::render($content, $attribs, $element);
 }
开发者ID:coolms,项目名称:twbs,代码行数:24,代码来源:ControlLabel.php

示例13: render

 /**
  * Render the captcha
  *
  * @param  ElementInterface          $element
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $captcha = $element->getCaptcha();
     if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
         throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute of type Zend\\Captcha\\Image; none found', __METHOD__));
     }
     $captcha->generate();
     $imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'alt' => $captcha->getImgAlt(), 'src' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix());
     if ($element->hasAttribute('id')) {
         $imgAttributes['id'] = $element->getAttribute('id') . '-image';
     }
     $closingBracket = $this->getInlineClosingBracket();
     $img = sprintf('<img %s%s', $this->createAttributesString($imgAttributes), $closingBracket);
     $position = $this->getCaptchaPosition();
     $separator = $this->getSeparator();
     $captchaInput = $this->renderCaptchaInputs($element);
     $pattern = '%s%s%s';
     if ($position == self::CAPTCHA_PREPEND) {
         return sprintf($pattern, $captchaInput, $separator, $img);
     }
     return sprintf($pattern, $img, $separator, $captchaInput);
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:29,代码来源:Image.php

示例14: render

 public function render(ElementInterface $element, $labelPosition = null)
 {
     $label = $element->getLabel();
     if (isset($label) && '' !== $label) {
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
     }
     if (is_null($labelPosition)) {
         $labelPosition = $this->labelPosition;
     }
     //        $inputErrorClass = $this->getInputErrorClass();
     //        if (count($element->getMessages()) > 0 && !empty($inputErrorClass)) {
     //            $element = $this->addClass($element, $inputErrorClass);
     //        }
     if ($this->partial) {
         $vars = ['element' => $element, 'label' => $label, 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $labelPosition, 'renderErrors' => $this->renderErrors];
         return $this->view->render($this->partial, $vars);
     }
     $labelHelper = $this->getLabelHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     if ($element->getOption('form-horizontal')) {
         $labelCols = (int) $element->getOption('label-cols') ?: 3;
         $inputCols = (int) $element->getOption('input-cols') ?: 12 - $labelCols;
     }
     if (isset($label) && '' !== $label && $element->getAttribute('type') !== 'hidden') {
         $attributes = ['class' => 'control-label'];
         if (isset($labelCols)) {
             $attributes['class'] .= sprintf(' col-sm-%d', $labelCols);
         }
         if ($element->hasAttribute('id')) {
             $attributes['for'] = $element->getAttribute('id');
         }
         $labelString = $labelHelper->openTag($attributes) . $label . $labelHelper->closeTag();
     } else {
         $labelString = '';
     }
     $elementString = $elementHelper->render($element);
     if ($this->renderErrors) {
         $errorsString = $elementErrorsHelper->render($element);
     } else {
         $errorsString = '';
     }
     $arguments = ['class' => 'form-group'];
     if (count($element->getMessages()) > 0) {
         $arguments['class'] .= ' ' . $this->inputErrorClass;
     }
     $html = $this->openTag($arguments);
     if ($labelPosition === self::LABEL_PREPEND) {
         $html .= $labelString;
     }
     if (isset($inputCols)) {
         $attributes = ['class' => sprintf('col-sm-%d', $inputCols)];
         if ($labelString === '') {
             $attributes['class'] .= sprintf(' col-sm-offset-%d', $labelCols);
         }
         $html .= sprintf('<div %s>', $this->createAttributesString($attributes));
     }
     $prependMarkup = $element->getOption('prepend-markup') ?: '';
     $appendMarkup = $element->getOption('append-markup') ?: '';
     $html .= $prependMarkup;
     $html .= $elementString;
     $html .= $appendMarkup;
     $html .= $errorsString;
     if (isset($inputCols)) {
         $html .= '</div>';
     }
     if ($labelPosition === self::LABEL_APPEND) {
         $html .= $labelString;
     }
     $html .= '</div>';
     return $html;
 }
开发者ID:phower,项目名称:zf2-bootstrap3-module,代码行数:74,代码来源:FormRow.php

示例15: render

 public function render(ElementInterface $element, $isHorizontal = false, $labelColumns = 2)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $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());
         }
     }
     $type = $element->getAttribute('type');
     if ($type != 'checkbox' && $type != 'submit' && $type != 'button' && $type != 'radio' && $type != 'file' && $type != 'multi_checkbox') {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . 'form-control';
         $element->setAttribute('class', $classAttributes);
     } elseif ($type == 'button' || $type == 'submit') {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . 'btn';
         $element->setAttribute('class', $classAttributes);
     }
     // 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 = ['element' => $element, 'label' => $label, 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors];
         return $this->view->render($this->partial, $vars);
     }
     $elementErrors = '';
     if ($this->renderErrors) {
         $elementErrors = $elementErrorsHelper->render($element, ['class' => 'text-danger']);
     }
     $elementString = $elementHelper->render($element);
     $addonAppend = $element->getOption('addon-append');
     $addonPrepend = $element->getOption('addon-prepend');
     if ($addonAppend !== null || $addonPrepend !== null) {
         $addonString = '<div class="input-group">';
         $addonString .= $this->addAddon($addonPrepend);
         $addonString .= $elementString;
         $addonString .= $this->addAddon($addonAppend);
         $addonString .= '</div>';
         $elementString = $addonString;
     }
     $elementString .= $this->getHelpBlock($element);
     // hidden elements do not need a <label> -https://github.com/zendframework/zf2/issues/5607
     if (isset($label) && '' !== $label && $type !== 'hidden') {
         $labelAttributes = [];
         if ($element instanceof LabelAwareInterface) {
             $labelAttributes = $element->getLabelAttributes();
         }
         if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
             $label = $escapeHtmlHelper($label);
         }
         if (empty($labelAttributes)) {
             $labelAttributes = $this->labelAttributes;
         }
         if (!$element->getAttribute('id') && $element->getName()) {
             $element->setAttribute('id', $element->getName());
         }
         if ($element->getAttribute('id')) {
             $labelAttributes['for'] = $element->getAttribute('id');
         }
         if ($isHorizontal) {
             $labelAttributes['class'] = ' control-label col-sm-' . $labelColumns;
             if ($element instanceof LabelAwareInterface) {
                 $element->setLabelAttributes(['class' => 'control-label col-sm-' . $labelColumns]);
             }
         } else {
             $labelAttributes['class'] = ' control-label';
             if ($element instanceof LabelAwareInterface) {
                 $element->setLabelAttributes(['class' => 'control-label']);
             }
         }
         // 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
         if (!$isHorizontal && ($type === 'multi_checkbox' || $type === 'radio' || $element instanceof MonthSelect)) {
             $markup = sprintf('<fieldset class="radio"><legend>%s</legend>%s</fieldset>', $label, $elementString);
         } elseif ($type == 'checkbox') {
             // Checkboxes need special treatment too
             if ($isHorizontal) {
                 $markup = '<div class="form-group"><div class="checkbox col-xs-' . (12 - $labelColumns) . ' col-xs-offset-' . $labelColumns . '"><label>' . $elementString . $label . '</label></div></div>';
             } else {
                 $markup = '<div class="checkbox"><label>' . $elementString . $label . '</label></div>';
             }
         } else {
             // Ensure element and label will be separated if element has an `id`-attribute.
             // If element has label option `always_wrap` it will be nested in any case.
             if ($element->hasAttribute('id') && ($element instanceof LabelAwareInterface && !$element->getLabelOption('always_wrap'))) {
                 $labelOpen = '';
                 $labelClose = '';
                 $label = $labelHelper($element);
             } else {
                 $labelOpen = $labelHelper->openTag($labelAttributes);
                 $labelClose = $labelHelper->closeTag();
//.........这里部分代码省略.........
开发者ID:Primetron,项目名称:Edusoft,代码行数:101,代码来源:FormRow.php


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