示例#1
0
 public function render(ElementInterface $element = null)
 {
     if ($element->getMessages()) {
         $element->setAttribute('class', 'error ' . $element->getAttribute('class'));
     }
     return parent::render($element);
 }
 /**
  * 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;
 }
 public function render(ElementInterface $element)
 {
     if ($element->getOption('static')) {
         return $this->getView()->formElementStatic($element);
     }
     return parent::render($element);
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
 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;
 }
示例#6
0
 /**
  * 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());
 }
示例#7
0
    /**
     * {@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;
    }
示例#8
0
 public function render(ElementInterface $element)
 {
     if (in_array($element->getAttribute('type'), array('html'))) {
         return $element->getValue();
     }
     return parent::render($element);
 }
示例#9
0
文件: Image.php 项目: Andyyang1981/pi
 /**
  * {@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);
 }
示例#10
0
 /**
  * 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')));
 }
示例#11
0
 /**
  * {@inheritDoc}
  */
 public function remove($elementOrFieldset)
 {
     if (!parent::has($elementOrFieldset) && $elementOrFieldset === 'identity' && $this->identityElement) {
         $elementOrFieldset = $this->identityElement->getName();
     }
     return parent::remove($elementOrFieldset);
 }
示例#12
0
 /**
  * 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);
 }
示例#13
0
 /**
  * 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());
 }
示例#14
0
 /**
  * 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);
 }
示例#15
0
 public function __invoke(ElementInterface $element = null)
 {
     if ($element && !$element->hasAttribute('class')) {
         $this->addClasses($element, ['btn', 'btn-default']);
     }
     return parent::__invoke($element);
 }
示例#16
0
 /**
  * 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);
 }
示例#17
0
 public function init(ElementInterface $element)
 {
     $this->formElement = $element;
     if ($element->hasAttribute('template')) {
         $this->template = $element->getAttribute('template');
     }
 }
 /**
  * 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;
 }
示例#19
0
 /**
  * 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;
 }
示例#20
0
 /**
  * {@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);
 }
示例#21
0
    /**
     * Render ReCaptcha form elements
     *
     * @param  ElementInterface $element 
     * @return string
     */
    public function render(ElementInterface $element)
    {
        $attributes = $element->getAttributes();
        if (!isset($attributes['captcha']) 
            || !$attributes['captcha'] instanceof CaptchaAdapter
        ) {
            throw new Exception\DomainException(sprintf(
                '%s requires that the element has a "captcha" attribute implementing Zend\Captcha\AdapterInterface; none found',
                __METHOD__
            ));
        }

        $captcha = $attributes['captcha'];
        unset($attributes['captcha']);

        $name          = $element->getName();
        $id            = isset($attributes['id']) ? $attributes['id'] : $name;
        $challengeName = empty($name) ? 'recaptcha_challenge_field' : $name . '[recaptcha_challenge_field]';
        $responseName  = empty($name) ? 'recaptcha_response_field'  : $name . '[recaptcha_response_field]';
        $challengeId   = $id . '-challenge';
        $responseId    = $id . '-response';

        $markup = $captcha->getService()->getHtml($name);
        $hidden = $this->renderHiddenInput($challengeName, $challengeId, $responseName, $responseId);
        $js     = $this->renderJsEvents($challengeId, $responseId);

        return $hidden . $markup . $js;
    }
示例#22
0
 /**
  * Render a form <select> element from the provided $element
  *
  * @param  ElementInterface $element
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $name = $element->getName();
     if (empty($name)) {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $attributes = $element->getAttributes();
     if (!isset($attributes['options']) || !is_array($attributes['options']) && !$attributes['options'] instanceof Traversable) {
         throw new Exception\DomainException(sprintf('%s requires that the element has an array or Traversable "options" attribute; none found', __METHOD__));
     }
     $options = (array) $attributes['options'];
     unset($attributes['options']);
     $value = array();
     if (isset($attributes['value'])) {
         $value = $attributes['value'];
         $value = $this->validateMultiValue($value, $attributes);
         unset($attributes['value']);
     }
     $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));
 }
示例#23
0
 /**
  * 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;
 }
 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);
 }
示例#25
0
    /**
     * Render the captcha
     * 
     * @param  ElementInterface $element 
     * @return string
     */
    public function render(ElementInterface $element)
    {
        $attributes = $element->getAttributes();

        if (!isset($attributes['captcha']) 
            || !$attributes['captcha'] instanceof CaptchaAdapter
        ) {
            throw new Exception\DomainException(sprintf(
                '%s requires that the element has a "captcha" attribute of type Zend\Captcha\Figlet; none found',
                __METHOD__
            ));
        }
        $captcha = $attributes['captcha'];
        $captcha->generate();

        $figlet = sprintf(
            '<pre>%s</pre>',
            $captcha->getFiglet()->render($captcha->getWord())
        );

        $position     = $this->getCaptchaPosition();
        $separator    = $this->getSeparator();
        $captchaInput = $this->renderCaptchaInputs($element);

        $pattern = '%s%s%s';
        if ($position == self::CAPTCHA_PREPEND) {
            return sprintf($pattern, $captchaInput, $separator, $figlet);
        }

        return sprintf($pattern, $figlet, $separator, $captchaInput);
    }
示例#26
0
 public function render(ElementInterface $element)
 {
     if ($element->getOption('use-switch')) {
         $element->setAttribute('data-switch', '1');
     }
     return parent::render($element);
 }
示例#27
0
 public function __invoke(ElementInterface $element)
 {
     $elementHelper = $this->getElementHelper();
     $name = preg_replace('/[^a-z0-9_-]+/', '', $element->getName());
     $result = '<div id="custom' . $name . '">' . $elementHelper($element) . '</div>';
     return $result;
 }
示例#28
0
    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;
    }
示例#29
0
 /**
  * {@inheritDoc}
  */
 public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null)
 {
     if (!$content && !($content = $element->getOption('description'))) {
         return '';
     }
     return parent::render($content, $attribs, $element, $form);
 }
 /**
  * @see \Zend\Form\View\Helper\FormRadio::render()
  * @param \Zend\Form\ElementInterface $oElement
  * @return string
  */
 public function render(ElementInterface $oElement)
 {
     $aElementOptions = $oElement->getOptions();
     if (isset($aElementOptions['disable-twb']) && $aElementOptions['disable-twb'] == true) {
         $sSeparator = $this->getSeparator();
         $this->setSeparator('');
         $sReturn = parent::render($oElement);
         $this->setSeparator($sSeparator);
         return $sReturn;
     }
     if (isset($aElementOptions['inline']) && $aElementOptions['inline'] == true) {
         $sSeparator = $this->getSeparator();
         $this->setSeparator('');
         $oElement->setLabelAttributes(array('class' => 'radio-inline'));
         $sReturn = sprintf('%s', parent::render($oElement));
         $this->setSeparator($sSeparator);
         return $sReturn;
     }
     if (isset($aElementOptions['btn-group']) && $aElementOptions['btn-group'] == true) {
         $this->setSeparator('');
         $oElement->setLabelAttributes(array('class' => 'btn btn-primary'));
         return sprintf('<div class="btn-group" data-toggle="buttons">%s</div>', parent::render($oElement));
     }
     return sprintf(self::$checkboxFormat, parent::render($oElement));
 }