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


PHP ElementInterface::getValueOptions方法代码示例

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


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

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

示例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;
     $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

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

示例4: render

 /**
  * Render a form radio-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 RadioGroup) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zork\\Form\\Element\\RadioGroup', __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();
     $additionalAttribures = array('type' => 'radio', 'name' => $name, 'required' => empty($attributes['required']) ? null : 'required');
     $this->validTagAttributes = $this->validRadioGroupAttributes;
     return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), $this->renderRadios($options, $value, $additionalAttribures, $element->getOption('option_attribute_filters')));
 }
开发者ID:gridguyz,项目名称:zork,代码行数:34,代码来源:FormRadioGroup.php

示例5: 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 Radio) {
         $options = $element->getValueOptions();
         if (empty($options)) {
             if (($translator = $this->getTranslator()) !== null) {
                 return '<i>' . $translator->translate('default.empty', 'default') . '</i>';
             } else {
                 return '';
             }
         }
     }
     return parent::render($element);
 }
开发者ID:gridguyz,项目名称:zork,代码行数:22,代码来源:FormRadio.php

示例6: 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 MultiCheckbox) {
         $options = $element->getValueOptions();
         if (empty($options)) {
             if (($translator = $this->getTranslator()) !== null) {
                 return '<i>' . $translator->translate('default.empty', 'default') . '</i>';
             } else {
                 return '';
             }
         }
     }
     return '<div class="multi_checkbox">' . parent::render($element) . '</div>';
 }
开发者ID:gridguyz,项目名称:zork,代码行数:22,代码来源:FormMultiCheckbox.php

示例7: render

 /**
  * Render a form <select> element from the provided $element
  *
  * @param  ElementInterface $element
  * @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 (empty($options)) {
         throw new Exception\DomainException(sprintf('%s requires that the element has "value_options"; none found', __METHOD__));
     }
     $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;
     return sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value));
 }
开发者ID:nuxwin,项目名称:zf2,代码行数:28,代码来源:FormSelect.php

示例8: prepareLabel

 protected function prepareLabel(ElementInterface $element)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $valuesOptions = $element->getValueOptions();
     //append span with c-indicator for each option
     foreach ($valuesOptions as $key => $optionSpec) {
         if (is_scalar($optionSpec)) {
             $optionSpec = ['label' => $optionSpec, 'value' => $key];
         }
         if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
             $optionSpec['label'] = $escapeHtmlHelper($optionSpec['label']);
         }
         $optionSpec['label'] = '<span class="c-indicator"></span>' . $optionSpec['label'];
         $valuesOptions[$key] = $optionSpec;
     }
     //disable escape because it was already used above
     $element->setLabelOption('disable_html_escape', true);
     $element->setValueOptions($valuesOptions);
 }
开发者ID:fagundes,项目名称:zff-base,代码行数:19,代码来源:BsFormRow.php

示例9: renderSummaryElement

 /**
  * Helper function to recurse into form elements when rendering summary.
  *
  * @param ElementInterface $element
  * @return string
  */
 protected function renderSummaryElement(ElementInterface $element)
 {
     if ($element instanceof Hidden || false === $element->getOption('render_summary')) {
         return '';
     }
     if ($element instanceof ViewPartialProviderInterface) {
         $renderer = $this->getView();
         /* @var $renderer \Zend\View\Renderer\PhpRenderer */
         $origPartial = $element->getViewPartial();
         $partial = "{$origPartial}.view";
         $partialParams = array('element' => $element);
         if (!$renderer->resolver($partial)) {
             $partial = $origPartial;
             $partialParams['renderSummary'] = true;
         }
         return $renderer->partial($partial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         /* @var $element EmptySummaryAwareInterface|ElementInterface */
         $emptySummaryNotice = $this->getTranslator()->translate($element->getEmptySummaryNotice(), $this->getTranslatorTextDomain());
         $markup = sprintf('<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', $element->getAttribute('id'), $emptySummaryNotice);
         return $markup;
     }
     $label = $this->getTranslator()->translate($element->getLabel());
     $markup = '';
     if ($element instanceof FieldsetInterface) {
         if (!$element instanceof FormInterface && $label) {
             $markup .= '<h4>' . $label . '</h4>';
         }
         foreach ($element as $el) {
             $markup .= $this->renderSummaryElement($el);
         }
         return $markup;
     }
     $elementValue = $element instanceof \Zend\Form\Element\Textarea ? nl2br($element->getValue()) : $element->getValue();
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) {
         $options = $element->getValueOptions();
         $translator = $this->getTranslator();
         if (true == $element->getAttribute('multiple')) {
             $multiOptions = [];
             foreach ($elementValue as $optionKey) {
                 if (isset($options[$optionKey])) {
                     $multiOptions['__general__'][] = $translator->translate($options[$optionKey]);
                     continue;
                 }
                 foreach ($options as $optKey => $optVal) {
                     if (!is_array($optVal) || !array_key_exists($optionKey, $optVal['options'])) {
                         continue;
                     }
                     $optGroupLabel = isset($optVal['label']) ? $translator->translate($optVal['label']) : $optKey;
                     $multiOptions[$optGroupLabel][] = $translator->translate($optVal['options'][$optionKey]);
                 }
             }
             $elementValue = [];
             foreach ($multiOptions as $optGroupLabel => $vals) {
                 $elementValue[] = "<b>{$optGroupLabel}</b><br>" . join(', ', $vals);
             }
             $elementValue = join('<br>', $elementValue) . '<br>';
         } else {
             $elementValue = $translator->translate($options[$elementValue]);
         }
     }
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\File) {
         return '';
     }
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }
开发者ID:utrenkner,项目名称:YAWIK,代码行数:80,代码来源:SummaryForm.php

示例10: render

 public function render(ElementInterface $element)
 {
     $type = $element->getAttribute('type');
     if ($type == 'multi_checkbox' || $type == "radio") {
         $aOptions = $element->getValueOptions();
         $aAtributes = $element->getOptions();
         $aClasse = $element->getAttributes();
         $aClasse = explode(" ", @$aClasse["class"]);
         $sType = $type;
         $selected = $element->getValue();
         $disabled = $element->getAttribute("disabled");
         foreach ($aOptions as $sKey => $aOption) {
             if (is_scalar($aOption)) {
                 $aOption = array('label' => " " . $aOption, 'value' => $sKey);
             }
             $aOption['label_attributes'] = array();
             $classe = "";
             if (!in_array("not-bootstrap", $aClasse)) {
                 $classe = "btn btn-default ";
                 if ($type == "multi_checkbox") {
                     if (@in_array($sKey, $selected)) {
                         $classe .= "active";
                     }
                 } else {
                     if ($type == "radio") {
                         if ($sKey == $selected) {
                             $classe .= "active";
                         }
                     }
                 }
             }
             if (in_array("not-bootstrap", $aClasse)) {
                 $classe .= "not-bootstrap";
             }
             if ($disabled) {
                 $classe .= " disabled";
             }
             if (empty($aOption['label_attributes']['class'])) {
                 $aOption['label_attributes']['class'] = trim($classe);
             } elseif (!preg_match('/(\\s|^)' . preg_quote($classe) . '(\\s|$)/', $aOption['label_attributes']['class'])) {
                 $aOption['label_attributes']['class'] .= trim(' ' . $classe);
             }
             if (isset($aAtributes['data'])) {
                 foreach ($aAtributes['data'] as $key => $value) {
                     $aOption['label_attributes']['data-' . $key] = $value[$sKey];
                 }
             }
             if ($disabled) {
                 if ($type == "multi_checkbox") {
                     if (@in_array($sKey, $selected)) {
                         $aOptions[$sKey] = $aOption;
                     } else {
                         unset($aOptions[$sKey]);
                     }
                 } else {
                     if ($type == "radio") {
                         if ($sKey == $selected) {
                             $aOptions[$sKey] = $aOption;
                         } else {
                             unset($aOptions[$sKey]);
                         }
                     }
                 }
             } else {
                 $aOptions[$sKey] = $aOption;
             }
         }
         $element->setValueOptions($aOptions);
         if (!in_array("not-bootstrap", $aClasse)) {
             return sprintf('<div><div class="btn-group" data-toggle="buttons">%s</div></div>', parent::render($element));
         } else {
             return sprintf('<div>%s</div>', parent::render($element));
         }
     }
     return parent::render($element);
 }
开发者ID:bhcosta90,项目名称:zend,代码行数:76,代码来源:FormElement.php

示例11: renderSummaryElement

 /**
  * Helper function to recurse into form elements when rendering summary.
  * 
  * @param ElementInterface $element
  * @return string
  */
 protected function renderSummaryElement(ElementInterface $element)
 {
     if ($element instanceof Hidden || false === $element->getOption('render_summary')) {
         return '';
     }
     if ($element instanceof ViewPartialProviderInterface) {
         $renderer = $this->getView();
         /* @var $renderer \Zend\View\Renderer\PhpRenderer */
         $origPartial = $element->getViewPartial();
         $partial = "{$origPartial}.view";
         $partialParams = array('element' => $element);
         if (!$renderer->resolver($partial)) {
             $partial = $origPartial;
             $partialParams['renderSummary'] = true;
         }
         return $renderer->partial($partial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         /* @var $element EmptySummaryAwareInterface|ElementInterface */
         $emptySummaryNotice = $this->getTranslator()->translate($element->getEmptySummaryNotice(), $this->getTranslatorTextDomain());
         $markup = sprintf('<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', $element->getAttribute('id'), $emptySummaryNotice);
         return $markup;
     }
     $label = $this->getTranslator()->translate($element->getLabel());
     $markup = '';
     if ($element instanceof FieldsetInterface) {
         if (!$element instanceof FormInterface && $label) {
             $markup .= '<h4>' . $label . '</h4>';
         }
         foreach ($element as $el) {
             $markup .= $this->renderSummaryElement($el);
         }
         return $markup;
     }
     $elementValue = $element instanceof \Zend\Form\Element\Textarea ? nl2br($element->getValue()) : $element->getValue();
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) {
         $options = $element->getValueOptions();
         $elementValue = $this->getTranslator()->translate($options[$elementValue]);
     }
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }
开发者ID:vfulco,项目名称:YAWIK,代码行数:54,代码来源:SummaryForm.php

示例12: render

 public function render(\Zend\Form\ElementInterface $oElement)
 {
     if ($oElement->getOption('value_only') === true) {
         $escapeHtml = true;
         $sValue = $oElement->getValue();
         if ($oElement instanceof \Zend\Form\Element\Select) {
             if (!is_array($sValue) && isset($oElement->getValueOptions()[$sValue])) {
                 $sValue = $oElement->getValueOptions()[$sValue];
             } elseif (is_array($sValue)) {
                 foreach ($sValue as $key => $value) {
                     if (isset($oElement->getValueOptions()[$value])) {
                         $sValue[$key] = $oElement->getValueOptions()[$value];
                     }
                 }
             }
         } elseif ($oElement instanceof \Zend\Form\Element\MultiCheckbox) {
             if ($oElement->getLabelOption('disable_html_escape')) {
                 $escapeHtml = false;
             }
             $valueOptions = $oElement->getValueOptions();
             if (!is_array($sValue)) {
                 $sValue = array($sValue);
             }
             foreach ($sValue as $key => $value) {
                 foreach ($valueOptions as $vOpt) {
                     if ($vOpt['value'] == $value) {
                         $sValue[$key] = $vOpt['label'];
                         break;
                     }
                 }
             }
         }
         // ignore buttons
         if ($oElement instanceof \Zend\Form\Element\Button || $oElement instanceof \Zend\Form\Element\Submit) {
             return '';
         }
         // hide passwords
         if ($oElement instanceof \Zend\Form\Element\Password) {
             $sValue = '*******';
         }
         // hide hidden fields
         if ($oElement instanceof Hidden) {
             $sValue = '';
         }
         if (is_array($sValue)) {
             $sValue = implode(', ', $sValue);
         }
         $valueHtml = $sValue;
         if ($escapeHtml) {
             $valueHtml = $this->getEscapeHtmlHelper()->__invoke($valueHtml);
         }
         if ($oElement->getOption('value_use_pre') === true) {
             $valueHtml = '<pre>' . $valueHtml . '</pre>';
         }
         $hidden = '';
         if ($oElement->getOption('add_hidden')) {
             // use default hidden element if requested
             $hiddenElement = new Hidden($oElement->getName());
             $hiddenElement->setValue($oElement->getValue());
             $hidden = $this->render($hiddenElement);
         }
         return sprintf('<div class="%s">%s</div>', 'form-value-only', $valueHtml) . $hidden;
     }
     return parent::render($oElement);
 }
开发者ID:xelax90,项目名称:xelax-twb-unmask,代码行数:65,代码来源:FormElement.php


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