Example #1
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));
 }
Example #2
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;
    }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * 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));
 }
Example #5
0
 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));
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
    /**
     * Render a form captcha for an element
     * 
     * @param  ElementInterface $element 
     * @return string
     * @throws Exception\DomainException if the element does not compose a captcha, or the renderer is not Pluggable
     */
    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'];
        $helper  = $captcha->getHelperName();

        $renderer = $this->getView();
        if (!$renderer instanceof Pluggable) {
            throw new Exception\DomainException(sprintf(
                '%s requires that the renderer implements Zend\Loader\Pluggable; it does not',
                __METHOD__
            ));
        }

        $helper = $renderer->plugin($helper);
        return $helper($element);
    }
Example #8
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;
    }
Example #9
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);
    }
Example #10
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);
 }
Example #11
0
 /**
  * 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;
 }
Example #12
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());
 }
 /**
  * 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;
 }
Example #14
0
 /**
  * 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));
 }
Example #15
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());
 }
Example #16
0
 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']);
 }
 /**
  * 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;
 }
Example #18
0
 /**
  * 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());
 }
Example #19
0
 /**
  * @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;
 }
 /**
  * Render a form <textarea> element from the provided $element
  *
  * @param  ElementInterface $element
  * @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;
     $content = (string) $element->getValue();
     $escapeHtml = $this->getEscapeHtmlHelper();
     return sprintf('<textarea %s>%s</textarea>', $this->createAttributesString($attributes), $escapeHtml($content));
 }
 /**
  * Renders the form row as a bootstrap form row
  *
  * @param ElementInterface $element
  * @param null $labelPosition
  * @return string
  */
 public function render(ElementInterface $element, $labelPosition = null)
 {
     if ($element->getAttribute('type') != 'submit') {
         $elementAttributes = $element->getAttributes();
         if (isset($elementAttributes['class']) && $elementAttributes['class'] != null) {
             $elementAttributes['class'] .= ' form-control';
         } else {
             $elementAttributes['class'] = 'form-control';
         }
         $element->setAttributes($elementAttributes);
     }
     $row = parent::render($element, $labelPosition);
     return '<div class="form-group">' . $row . '</div>';
 }
Example #22
0
 /**
  * {@inheritDoc}
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof MonthSelectElement) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type %s', __METHOD__, MonthSelectElement::class));
     }
     $elementAttribs = $element->getAttributes();
     unset($elementAttribs['name']);
     $id = $this->getId($element);
     $attribs = $element->getYearAttributes();
     $element->setYearAttributes(array_replace_recursive($elementAttribs, empty($attribs['id']) ? ['id' => (empty($elementAttribs['id']) ? $id : $elementAttribs['id']) . '-year'] : [], $attribs));
     $attribs = $element->getMonthAttributes();
     $element->setMonthAttributes(array_replace_recursive($elementAttribs, empty($attribs['id']) ? ['id' => (empty($elementAttribs['id']) ? $id : $elementAttribs['id']) . '-month'] : [], $attribs));
     return parent::render($element);
 }
Example #23
0
 /**
  * Render captcha form elements for the given element
  *
  * Creates and returns:
  * - Hidden input with captcha identifier (name[id])
  * - Text input for entering captcha value (name[input])
  *
  * More specific renderers will consume this and render it.
  *
  * @param  ElementInterface $element
  * @throws Exception\DomainException
  * @return string
  */
 protected function renderCaptchaInputs(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();
     $captcha = $element->getCaptcha();
     if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
         throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute implementing Zend\\Captcha\\AdapterInterface; none found', __METHOD__));
     }
     $hidden = $this->renderCaptchaHidden($captcha, $attributes);
     $input = $this->renderCaptchaInput($captcha, $attributes);
     return $hidden . $input;
 }
Example #24
0
 /**
  * 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 '';
     }
     $attributes = $element->getAttributes();
     $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) {
         $label = $element->getLabel();
         $legend = '';
         if (!empty($label)) {
             if (null !== ($translator = $this->getTranslator())) {
                 $label = $translator->translate($label, $this->getTranslatorTextDomain());
             }
             $label = $escapeHtmlHelper($label);
             $legend = sprintf('<legend>%s</legend>', $label);
         }
         $attributesString = $this->createAttributesString($attributes);
         if (!empty($attributesString)) {
             $attributesString = ' ' . $attributesString;
         }
         $markup = sprintf('<fieldset%s>%s%s</fieldset>', $attributesString, $legend, $markup);
     }
     return $markup;
 }
Example #25
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 Properties) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Grid\\Customize\\Form\\Element\\Properties', __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();
     $value = (array) $element->getValue();
     $addAttr = array('name' => $name, 'required' => empty($attributes['required']) ? null : 'required');
     unset($attributes['name']);
     unset($attributes['required']);
     $this->validTagAttributes = $this->validContainerAttributes;
     return sprintf('<dl %s>%s</dl>', $this->createAttributesString($attributes), $this->renderProperties($value, $addAttr));
 }
 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__));
     }
     $label = $element->getLabel();
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['type'] = $this->getInputType();
     $attributes['class'] = 'sr-only';
     $attributes['value'] = $element->getValue();
     $closingBracket = $this->getInlineClosingBracket();
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $rendered = '<div class="radio"><label class="radio-custom" data-initialize="radio">' . $input . '</label>' . $label . '</div>';
     return $rendered;
 }
Example #27
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 GlobalBanners) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Grid\\Banner\\Form\\Element\\GlobalBanners', __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();
     $value = (array) $element->getValue();
     $label = $this->label;
     if ($this->isTranslatorEnabled() && $this->hasTranslator()) {
         $label = $this->getTranslator()->translate($label, $this->getTranslatorTextDomain());
     }
     unset($attributes['name']);
     return $this->renderBannerGroups($name, $attributes, array(array('header' => $label, 'markup' => $this->renderBanners($name, $value), 'attributes' => array())));
 }
 /**
  * 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';
     $divClass = isset($attributes['class']) ? $attributes['class'] : 'form-control';
     $attributes['class'] = 'form-control input-mini spinbox-input';
     $attributes['value'] = $element->getValue();
     $closingBracket = $this->getInlineClosingBracket();
     $jsAttributes = array();
     if (isset($attributes['min'])) {
         $jsAttributes['min'] = $attributes['min'];
         unset($attributes['min']);
     }
     if (isset($attributes['max'])) {
         $jsAttributes['max'] = $attributes['max'];
         unset($attributes['max']);
     }
     if (isset($attributes['step'])) {
         $jsAttributes['step'] = $attributes['step'];
         unset($attributes['step']);
     }
     if (isset($attributes['units'])) {
         $jsAttributes['units'] = $attributes['units'];
         unset($attributes['units']);
     }
     $script = $this->scriptAttributes($name, $jsAttributes);
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $spinBox = '';
     $spinBox .= '<div class="spinbox-buttons btn-group btn-group-vertical">';
     $spinBox .= '<button type="button" class="btn btn-default spinbox-up btn-xs">';
     $spinBox .= '<span class="glyphicon glyphicon-chevron-up"></span><span class="sr-only">Increase</span>';
     $spinBox .= '</button>';
     $spinBox .= '<button type="button" class="btn btn-default spinbox-down btn-xs">';
     $spinBox .= '<span class="glyphicon glyphicon-chevron-down"></span><span class="sr-only">Decrease</span>';
     $spinBox .= '</button>';
     $spinBox .= '</div>';
     $rendered = '<div class="' . $divClass . '">' . $script . '<div class="spinbox" id="' . $name . '">' . $input . $spinBox . '</div></div>';
     return $rendered;
 }
Example #29
0
 /**
  * Renders editor contents
  *
  * @param  ElementInterface $element
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $options = array_merge($this->getOptions(), $element->getOptions());
     $attributes = array_merge($this->getAttributes(), $element->getAttributes());
     // Set up language
     if (!isset($options['language'])) {
         $options['language'] = Pi::service('i18n')->locale;
     }
     $options['language'] = strtolower(str_replace('_', '-', $options['language']));
     $basePath = isset($options['base_path']) ? $options['base_path'] : Pi::path('www') . '/script/editor/ckeditor';
     include_once $basePath . '/ckeditor.php';
     include_once __DIR__ . '/Ckeditor.php';
     $baseUrl = isset($options['base_url']) ? $options['base_url'] : Pi::url('www') . '/script/editor/ckeditor/';
     $ckEditor = new Ckeditor($baseUrl);
     $ckEditor->returnOutput = true;
     $ckEditor->textareaAttributes = array_merge($ckEditor->textareaAttributes, $attributes);
     $this->setupFinder($ckEditor, $options);
     return $ckEditor->editor($element->getName(), $element->getValue(), $options);
 }
Example #30
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\\Image; none found', __METHOD__));
     }
     $captcha = $attributes['captcha'];
     $captcha->generate();
     $imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'alt' => $captcha->getImgAlt(), 'src' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix());
     $closingBracket = $this->getInlineClosingBracket();
     $img = sprintf('<img %s%s', $this->createAttributesString($imgAttributes), $closingBracket);
     $position = $this->getCaptchaPosition();
     $separator = $this->getSeparator();
     $captchaInput = $this->renderCaptchaInputs($element);
     $pattern = '%s%s%s';
     if ($position == self::CAPTCHA_PREPEND) {
         return sprintf($pattern, $captchaInput, $separator, $img);
     }
     return sprintf($pattern, $img, $separator, $captchaInput);
 }