作者:3makk
项目:Foundatio
public function render(ElementInterface $element = null)
{
if ($element->getMessages()) {
$element->setAttribute('class', 'error ' . $element->getAttribute('class'));
}
return parent::render($element);
}
作者:gstearmi
项目:EshopVegeTabl
/**
* Returns the control group open tag
* @param ElementInterface $element
* @return string
*/
public function openTag(ElementInterface $element)
{
$class = 'controls';
$id = 'controls-' . $element->getName();
$html = sprintf('<div class="%s" id="%s">', $class, $id);
return $html;
}
作者:phowe
项目:zf2-bootstrap3-modul
public function render(ElementInterface $element)
{
if ($element->getOption('static')) {
return $this->getView()->formElementStatic($element);
}
return parent::render($element);
}
作者:vfulc
项目:YAWI
/**
* 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;
}
作者:rafajaque
项目:colloquiu
public function render(ElementInterface $element)
{
/* just a reminder. the types are:
checkbox, color, date, datetime, datetime-local, email, file, hidden
image, month, multi_checkbox, number, password, radio, range, reset
search, select, submit, tel, text, textarea, time, url, week
*/
$labelHelper = $this->getLabelHelper();
$escapeHelper = $this->getEscapeHtmlHelper();
$elementHelper = $this->getElementHelper();
$elementErrorHelper = $this->getElementErrorHelper();
$descriptionHelper = $this->getDescriptionHelper();
$groupWrapper = $groupWrapper ?: $this->groupWrapper;
$controlWrapper = $controlWrapper ?: $this->controlWrapper;
$id = $element->getAttribute('id') ?: $element->getAttribute('name');
$html = "";
$label = $element->getAttribute('label');
if ($label) {
$html .= $labelHelper->openTag(array('for' => $id, 'class' => 'control-label'));
// todo allow for not escaping the label
$html .= $escapeHelper($label);
$html .= $labelHelper->closeTag();
}
$html .= sprintf($controlWrapper, $id, $elementHelper->render($element), $descriptionHelper->render($element), $elementErrorHelper->render($element));
$addtClass = $element->getMessages() ? ' error' : '';
echo $element->getLabel();
die;
$output .= parent::render($element);
return $output;
}
作者:skp
项目:bootstra
/**
* 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());
}
作者:Andyyang198
项目:p
/**
* {@inheritDoc}
*/
public function render(ElementInterface $element)
{
if (!$element instanceof LoginFieldElement) {
return '';
}
$fields = $element->getFields();
if (1 == count($fields)) {
$element->setAttribute('placeholder', current($fields));
return parent::render($element);
}
$template = $element->getOption('template') ?: '<div class="input-group">%s</div>';
$pattern = <<<EOT
<input name="%s[0]" %s%s
<span class="input-group-addon">
<select class="pull-right" name="%s[1]">
%s
</select>
</span>
EOT;
$name = $element->getName();
list($value, $field) = $element->getValue();
$attributes = array_replace($element->getAttributes(), array('type' => 'text', 'value' => $value));
if (!isset($attributes['class'])) {
$attributes['class'] = 'form-control';
}
$attribString = $this->createAttributesString($attributes);
$patternField = '<option value="%s"%s>%s</option>' . PHP_EOL;
$fieldString = '';
foreach ($fields as $key => $label) {
$class = $field == $key ? ' selected' : '';
$fieldString .= sprintf($patternField, $key, $class, $label);
}
$html = sprintf($template, sprintf($pattern, $name, $attribString, $this->getInlineClosingBracket(), $name, $fieldString));
return $html;
}
作者:ualisonaguia
项目:shome
public function render(ElementInterface $element)
{
if (in_array($element->getAttribute('type'), array('html'))) {
return $element->getValue();
}
return parent::render($element);
}
作者:Andyyang198
项目:p
/**
* {@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);
}
作者:gridguy
项目:zor
/**
* 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')));
}
作者:dannytru
项目:dlutwbootstra
/**
* 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');
}
$element->setLabelAttributes($labelAttributes);
$formLabelHelper = $this->formLabelHelper;
return $formLabelHelper($element, $labelContent);
}
作者:bix0
项目:Stjornvis
/**
* 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());
}
作者:gridguy
项目:banne
/**
* 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);
}
作者:phowe
项目:zf2-bootstrap3-modul
public function __invoke(ElementInterface $element = null)
{
if ($element && !$element->hasAttribute('class')) {
$this->addClasses($element, ['btn', 'btn-default']);
}
return parent::__invoke($element);
}
作者:CATSInformatic
项目:CatsSy
/**
* 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);
}
作者:vfulc
项目:YAWI
public function init(ElementInterface $element)
{
$this->formElement = $element;
if ($element->hasAttribute('template')) {
$this->template = $element->getAttribute('template');
}
}
作者:Ellipizl
项目:ZF2DoctrineBas
/**
* Render a collection by iterating through all fieldsets and elements
*
* @param ElementInterface $element
* @return string
*/
public function render(ElementInterface $element)
{
$renderer = $this->getView();
if (!method_exists($renderer, 'plugin')) {
// Bail early if renderer is not pluggable
return '';
}
$markup = '';
$templateMarkup = '';
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$elementHelper = $this->getElementHelper();
$fieldsetHelper = $this->getFieldsetHelper();
if ($element instanceof CollectionElement && $element->shouldCreateTemplate()) {
$templateMarkup = $this->renderTemplate($element);
}
foreach ($element->getIterator() as $elementOrFieldset) {
if ($elementOrFieldset instanceof FieldsetInterface) {
$markup .= $fieldsetHelper($elementOrFieldset);
} elseif ($elementOrFieldset instanceof ElementInterface) {
$markup .= $elementHelper($elementOrFieldset);
}
}
// If $templateMarkup is not empty, use it for simplify adding new element in JavaScript
if (!empty($templateMarkup)) {
$markup .= $templateMarkup;
}
// Every collection is wrapped by a fieldset if needed
if ($this->shouldWrap) {
//Esto fue lo que se modificó para que trabajara con <div> en vez de <fieldset> - wyanez
$markup = sprintf('<div>%s</div>', $markup);
}
return $markup;
}
作者:Andyyang198
项目:p
/**
* Render editor
*
* @param ElementInterface $element
*
* @throws \Zend\Form\Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
$renderer = $this->getView();
if (!method_exists($renderer, 'plugin')) {
// Bail early if renderer is not pluggable
return '';
}
$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->getOptions();
/*
$attributes = $element->getAttributes();
$attributes['value'] = $element->getValue();
$options['attributes'] = $attributes;
*/
$editorType = $element->getOption('editor') ?: 'textarea';
$editor = EditorFactory::load($editorType, $options);
$html = '';
if ($editor) {
$html = $editor->setView($renderer)->render($element);
}
if (!$html) {
$html = $renderer->formTextarea($element);
}
return $html;
}
作者:coolm
项目:twb
/**
* {@inheritDoc}
*/
public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null)
{
if ($element) {
$element->setOption('input_group', true);
}
return parent::render($content, $attribs, $element, $form);
}
作者:eltondia
项目:Relogi
/**
* Render validation errors for the provided $element
*
* @param ElementInterface $element
* @param array $attributes
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element, array $attributes = array())
{
$messages = $element->getMessages();
if (empty($messages)) {
return '';
}
if (!is_array($messages) && !$messages instanceof Traversable) {
throw new Exception\DomainException(sprintf('%s expects that $element->getMessages() will return an array or Traversable; received "%s"', __METHOD__, is_object($messages) ? get_class($messages) : gettype($messages)));
}
// Prepare attributes for opening tag
$attributes = array_merge($this->attributes, $attributes);
$attributes = $this->createAttributesString($attributes);
if (!empty($attributes)) {
$attributes = ' ' . $attributes;
}
// Flatten message array
$escapeHtml = $this->getEscapeHtmlHelper();
$messagesToPrint = array();
$self = $this;
array_walk_recursive($messages, function ($item) use(&$messagesToPrint, $escapeHtml, $self) {
if (null !== ($translator = $self->getTranslator())) {
$item = $translator->translate($item, $self->getTranslatorTextDomain());
}
$messagesToPrint[] = $escapeHtml($item);
});
if (empty($messagesToPrint)) {
return '';
}
// Generate markup
$markup = sprintf($this->getMessageOpenFormat(), $attributes);
$markup .= implode($this->getMessageSeparatorString(), $messagesToPrint);
$markup .= $this->getMessageCloseString();
return $markup;
}