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


PHP ElementInterface::getAttributes方法代码示例

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


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

示例1: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws \Zend\Form\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__));
     }
     $checkedValue = $element->getCheckedValue();
     $uncheckedValue = $element->getUncheckedValue();
     $useHiddenElement = $element->useHiddenElement();
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['checked'] = '';
     $attributes['type'] = $this->getInputType();
     $closingBracket = $this->getInlineClosingBracket();
     $value = $element->getValue();
     if ($value === $checkedValue) {
         $attributes['checked'] = 'checked';
     }
     $attributes['value'] = $checkedValue;
     $rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     if ($useHiddenElement) {
         $hiddenAttributes = array('name' => $attributes['name'], 'value' => $uncheckedValue);
         $rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
     }
     return $rendered;
 }
开发者ID:Rovak,项目名称:zf2,代码行数:36,代码来源:FormCheckbox.php

示例2: render

 /**
  * Render a form <select> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\InvalidArgumentException
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof SelectElement) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __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__));
     }
     $options = $element->getValueOptions();
     if (($emptyOption = $element->getEmptyOption()) !== null) {
         $options = array('' => $emptyOption) + $options;
     }
     $attributes = $element->getAttributes();
     $value = $this->validateMultiValue($element->getValue(), $attributes);
     $attributes['name'] = $name;
     if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
         $attributes['name'] .= '[]';
     }
     $this->validTagAttributes = $this->validSelectAttributes;
     $size = $element->getOption('size');
     if (empty($size)) {
         return sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value));
     }
     return sprintf('<div class="col-lg-%s col-md-%s col-sm-%s col-xs-%s">
             <select %s>%s</select>
         </div>', $size, $size, $size, $size, $this->createAttributesString($attributes), $this->renderOptions($options, $value));
 }
开发者ID:skpd,项目名称:bootstrap,代码行数:36,代码来源:FormSelect.php

示例3: 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__));
     }
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $content = (string) $element->getValue();
     $escapeHtml = $this->getEscapeHtmlHelper();
     //ADD OPTIONS
     //	this should really be in Stjonvisi\Form\Element\Img
     //	but it gets overwritten at some point, so the simplest
     //	thing was to add it here.
     //	TODO place this i a more generic place
     $element->setOption('max', $this->getMaxSize())->setOption('mime', '/image\\/jpg|png|gif/')->setOption('url', '/skrar/mynd');
     //OPTIONS
     //	options are used to set attributes and values
     //	to the custom element. We therefore need to remove
     //	label, label_attributes and label_options before we
     //	can convert them into an attribute string.
     $options = $element->getOptions();
     unset($options['label']);
     unset($options['label_attributes']);
     unset($options['label_options']);
     $strings = array_map(function ($key, $value) {
         return sprintf('%s="%s"', $key, $value);
     }, array_keys($options), $options);
     return sprintf('<stjornvisi-rich %s><textarea %s>%s</textarea></stjornvisi-rich>', implode(' ', $strings), $this->createAttributesString($attributes), $escapeHtml($content));
 }
开发者ID:bix0r,项目名称:Stjornvisi,代码行数:30,代码来源:RichElement.php

示例4: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param ElementInterface $element Zend Form 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';
     }
     if ($element->getAttribute('class') != 'input-checkbox') {
         $rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     } else {
         if ($element->getAttribute('id') == '') {
             $element->setAttribute('id', 'checkbox-' . uniqid());
         }
         unset($attributes['class']);
         $rendered = sprintf('<span class="input-checkbox"><input %s%s<label for="%s"></label></span>', $this->createAttributesString($attributes), $closingBracket, $element->getAttribute('id'));
     }
     return $rendered;
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:37,代码来源:FormCheckbox.php

示例5: render

    public function render(ElementInterface $element)
    {
        $attributes = $element->getAttributes();
        if (isset($attributes['custom'])) {
            $custom = $attributes['custom'];
            unset($attributes['custom']);
            $element->setAttributes($attributes);
        }
        $prefix = '';
        $suffix = '';

        // Check on name for now
        if ($attributes['type'] === 'text' && $attributes['name'] === 'email') {
            $prefix .= '<div class="input-group">';
            $prefix .= '<span class="input-group-addon">@</span>';
            $suffix .= '<span class="input-group-addon" id="basic-addon2">@example.com</span>';
            $suffix .= '</div>';
        } elseif ($attributes['type'] === 'text' && $attributes['name'] === 'keyword') {
            $prefix .= '<div class="input-group">';
            $suffix .= '<span class="input-group-btn">';
            $suffix .= sprintf('<button class="btn btn-default" type="submit">%s</button>', $custom['label']);
            $suffix .= '</span>';
        }
        return $prefix . parent::render($element) . $suffix;
    }
开发者ID:jbarentsen,项目名称:drb,代码行数:25,代码来源:FormElementHelper.php

示例6: render

 /**
  * Render a form checkbox-group element from the provided $element
  *
  * @param   \Zend\Form\ElementInterface $element
  * @throws  \Zend\Form\Exception\InvalidArgumentException
  * @throws  \Zend\Form\Exception\DomainException
  * @return  string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof TagBanners) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Grid\\Banner\\Form\\Element\\TagBanners', __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__));
     }
     $appService = $this->getAppServiceHelper();
     $tagModel = $appService('Grid\\Tag\\Model\\Tag\\Model');
     $attributes = $element->getAttributes();
     $value = (array) $element->getValue();
     $groups = array();
     foreach ($value as $tagId => $banners) {
         $tag = $tagModel->find($tagId);
         if ($tag && $tag->locale) {
             $locale = 'locale.sub.' . $tag->locale;
             if ($this->isTranslatorEnabled() && $this->hasTranslator()) {
                 $locale = $this->getTranslator()->translate($locale, 'locale');
             }
         }
         $label = $tag ? $tag->name . (isset($locale) ? ' (' . $locale . ')' : '') : '#' . $tagId;
         $groups[] = array('header' => $label, 'markup' => $this->renderBanners($name . '[' . $tagId . ']', $banners), 'attributes' => array('data-tagid' => $tagId));
     }
     unset($attributes['name']);
     return $this->renderBannerGroups($name . '[__tagid__]', $attributes, $groups);
 }
开发者ID:gridguyz,项目名称:banner,代码行数:36,代码来源:FormBannerTags.php

示例7: render

 /**
  * Render a form <select> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\InvalidArgumentException
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof SelectElement) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __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__));
     }
     $options = $element->getValueOptions();
     if (($emptyOption = $element->getEmptyOption()) !== null) {
         $options = array('' => $emptyOption) + $options;
     }
     $attributes = $element->getAttributes();
     $value = $this->validateMultiValue($element->getValue(), $attributes);
     $attributes['name'] = $name;
     if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
         $attributes['name'] .= '[]';
     }
     $this->validTagAttributes = $this->validSelectAttributes;
     $rendered = sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value));
     // Render hidden element
     $useHiddenElement = method_exists($element, 'useHiddenElement') && method_exists($element, 'getUnselectedValue') && $element->useHiddenElement();
     if ($useHiddenElement) {
         $rendered = $this->renderHiddenElement($element) . $rendered;
     }
     return $rendered;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:36,代码来源:FormSelect.php

示例8: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $name = $element->getName();
     if ($name === null || $name === '') {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $attributes = $element->getAttributes();
     $attributes['type'] = $this->getType($element);
     $attributes['name'] = $name;
     if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
         $attributes['name'] .= '[]';
     }
     $value = $element->getValue();
     if (is_array($value) && isset($value['name']) && !is_array($value['name'])) {
         $attributes['value'] = $value['name'];
     } elseif (is_string($value)) {
         $attributes['value'] = $value;
     }
     $size = $element->getOption('size');
     if (empty($size)) {
         return sprintf('<input %s%s', $this->createAttributesString($attributes), $this->getInlineClosingBracket());
     }
     return sprintf('<div class="col-lg-%s col-md-%s col-sm-%s col-xs-%s">
             <input %s%s
         </div>', $size, $size, $size, $size, $this->createAttributesString($attributes), $this->getInlineClosingBracket());
 }
开发者ID:skpd,项目名称:bootstrap,代码行数:33,代码来源:FormFile.php

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

示例10: render

 /**
  * Render a form checkbox-group element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\InvalidArgumentException
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof MultiCheckboxGroup) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zork\\Form\\Element\\MutiCheckboxGroup', __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__));
     }
     $options = $element->getValueOptions();
     if (empty($options)) {
         if (($translator = $this->getTranslator()) !== null) {
             return '<i>' . $translator->translate('default.empty', 'default') . '</i>';
         } else {
             return '';
         }
     }
     if (($emptyOption = $element->getEmptyOption()) !== null) {
         $options = array('' => $emptyOption) + $options;
     }
     $attributes = $element->getAttributes();
     $value = $element->getValue();
     $addAttr = array('type' => 'checkbox', 'name' => substr($name, -2) == '[]' ? $name : $name . '[]', 'required' => empty($attributes['required']) ? null : 'required');
     $this->validTagAttributes = $this->validCheckboxGroupAttributes;
     if (null !== $element->getTranslatorTextDomain()) {
         $this->setTranslatorTextDomain($element->getTranslatorTextDomain());
     }
     if (empty($attributes['class'])) {
         $attributes['class'] = 'multi_checkbox';
     }
     return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), sprintf('<input type="hidden" name="%s" value="" />' . PHP_EOL, substr($name, -2) == '[]' ? substr($name, 0, -2) : $name) . $this->renderCheckboxes($options, $value, $addAttr));
 }
开发者ID:gridguyz,项目名称:zork,代码行数:40,代码来源:FormMultiCheckboxGroup.php

示例11: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $name = $element->getName();
     if ($name === null || $name === '') {
         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->getType($element);
     $attributes['value'] = $element->getValue();
     //ADD OPTIONS
     //	this should really be in Stjonvisi\Form\Element\Img
     //	but it gets overwritten at some point, so the simplest
     //	thing was to add it here.
     //	TODO place this i a more generic place
     $element->setOption('max', $this->getMaxSize())->setOption('url', '/skrar/mynd')->setOption('accept', 'image/*')->setOption('mime', '/image\\/jpg|jpeg|png|gif/');
     //OPTIONS
     //	options are used to set attributes and values
     //	to the custom element. We therefore need to remove
     //	label, label_attributes and label_options before we
     //	can convert them into an attribute string.
     $options = $element->getOptions();
     unset($options['label']);
     unset($options['label_attributes']);
     unset($options['label_options']);
     $strings = array_map(function ($key, $value) {
         return sprintf('%s="%s"', $key, $value);
     }, array_keys($options), $options);
     return sprintf('<stjornvisi-img %s><input %s%s</stjornvisi-img>', implode(' ', $strings), $this->createAttributesString($attributes), $this->getInlineClosingBracket());
 }
开发者ID:bix0r,项目名称:Stjornvisi,代码行数:37,代码来源:ImgElement.php

示例12: render

 public function render(ElementInterface $element)
 {
     $attributes = $element->getAttributes();
     // echo $this->createAttributesString($attributes);
     return sprintf('<video width="%s" height="%s" controls>
       <source src="%s" type="%s">
      </video>', $attributes['width'], $attributes['height'], $attributes['src'], $attributes['type']);
 }
开发者ID:trongle,项目名称:zend-2,代码行数:8,代码来源:FormVideo.php

示例13: 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)
 {
     $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'] = 'text';
     $attributes['class'] = 'form-control';
     $attributes['value'] = $element->getValue();
     $attributes['date'] = $element->getValue();
     $attributes['readonly'] = 'readonly';
     $closingBracket = $this->getInlineClosingBracket();
     $jsAttributes = array();
     if (isset($attributes['allowPastDates'])) {
         $jsAttributes['allowPastDates'] = $attributes['allowPastDates'];
         unset($attributes['allowPastDates']);
     }
     if (isset($attributes['date'])) {
         $jsAttributes['date'] = $attributes['date'];
         unset($attributes['date']);
     }
     if (isset($attributes['formatDate'])) {
         $jsAttributes['formatDate'] = $attributes['formatDate'];
         unset($attributes['formatDate']);
     }
     if (isset($attributes['momentConfig'])) {
         $jsAttributes['momentConfig'] = $attributes['momentConfig'];
         unset($attributes['momentConfig']);
     }
     if (isset($attributes['sameYearOnly'])) {
         $jsAttributes['sameYearOnly'] = $attributes['sameYearOnly'];
         unset($attributes['sameYearOnly']);
     }
     $script = $this->scriptAttributes($name, $jsAttributes);
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $wrapper = '<div class="dropdown-menu dropdown-menu-right datepicker-calendar-wrapper" role="menu">';
     $wrapper .= $this->calendar();
     $wrapper .= $this->monthWheel();
     $wrapper .= '</div>';
     $datePicker = '<div class="input-group">';
     $datePicker .= $input;
     $datePicker .= '<div class="input-group-btn">';
     $datePicker .= '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">';
     $datePicker .= '<span class="glyphicon glyphicon-calendar"></span>';
     $datePicker .= '<span class="sr-only">Toggle Calendar</span>';
     $datePicker .= '</button>';
     $datePicker .= $wrapper;
     $datePicker .= '</div>';
     $datePicker .= '</div>';
     $rendered = $script . '<div class="datepicker" id="' . $name . '">' . $datePicker . '</div>';
     return $rendered;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:62,代码来源:FormDate.php

示例14: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $name = $element->getName();
     if ($name === null || $name === '') {
         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->getType($element);
     return sprintf('<input %s%s', $this->createAttributesString($attributes), $this->getInlineClosingBracket());
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:17,代码来源:FormInput.php

示例15: initFormElement

 /**
  * @param ElementInterface $element
  *
  * @return \SxBootstrap\View\Helper\Bootstrap\Form\Input
  */
 protected function initFormElement(ElementInterface $element)
 {
     $this->name($element->getName())->type('text');
     $this->getElement()->addAttributes($element->getAttributes());
     $type = $element->getAttribute('type');
     if (null !== $type) {
         $this->type(strtolower($type));
     }
     $this->value($element->getValue());
     return $this;
 }
开发者ID:spoonx,项目名称:sxbootstrap,代码行数:16,代码来源:Input.php


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