コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: ToggleButton.php プロジェクト: vfulco/YAWIK
 /**
  * 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;
 }
コード例 #3
0
ファイル: FormBannerTags.php プロジェクト: gridguyz/banner
 /**
  * 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);
 }
コード例 #4
0
ファイル: RichElement.php プロジェクト: bix0r/Stjornvisi
 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));
 }
コード例 #5
0
ファイル: FormSelect.php プロジェクト: skpd/bootstrap
 /**
  * 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));
 }
コード例 #6
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));
 }
コード例 #7
0
ファイル: FormCheckbox.php プロジェクト: Rovak/zf2
 /**
  * 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;
 }
コード例 #8
0
ファイル: FormRow.php プロジェクト: ualisonaguiar/shome2
 public function render(ElementInterface $element)
 {
     if (in_array($element->getAttribute('type'), array('html'))) {
         return $element->getValue();
     }
     return parent::render($element);
 }
コード例 #9
0
 /**
  * Render a form <select> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws \Zend\Form\Exception\InvalidArgumentException
  * @throws \Zend\Form\Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof Reference) {
         throw new \Zend\Form\Exception\InvalidArgumentException(sprintf('%s requires that the element is of type MfccAdminModule\\Form\\Element\\Reference', __METHOD__));
     }
     $name = $element->getName();
     if (empty($name) && $name !== 0) {
         throw new \Zend\Form\Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $options = $element->getValueOptions();
     if (($emptyOption = $element->getEmptyOption()) !== null) {
         $options = ['' => $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;
 }
コード例 #10
0
ファイル: Submit.php プロジェクト: spoonx/sxbootstrap
 /**
  * {@InheritDoc}
  */
 protected function initFormElement(ElementInterface $element)
 {
     $value = $element->getValue();
     if (!empty($value)) {
         $this->value($value);
     }
     return parent::initFormElement($element);
 }
コード例 #11
0
ファイル: Button.php プロジェクト: spoonx/sxbootstrap
 /**
  * {@InheritDoc}
  */
 protected function initFormElement(ElementInterface $element)
 {
     $value = $element->getValue();
     if (!empty($value)) {
         $this->addAttribute('value', $this->translate($value));
     }
     return parent::initFormElement($element);
 }
コード例 #12
0
ファイル: Datepicker.php プロジェクト: Patinger/Browsergame
 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof Date) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Date', __METHOD__));
     }
     return '<div class="input-group date datetimepicker"  data-date-format="YYYY-MM-DD">
                 <input name="' . $element->getName() . '" type="text" class="form-control" value="' . $element->getValue() . '" />
                 <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
             </div>';
 }
コード例 #13
0
 public function getHiddenElement(ElementInterface $element)
 {
     if ($element instanceof Hidden) {
         return $element;
     }
     $name = $element->getName();
     $value = $element->getValue();
     $hidden = new Hidden($name);
     $hidden->setValue($value);
     return $hidden;
 }
コード例 #14
0
ファイル: Input.php プロジェクト: spoonx/sxbootstrap
 /**
  * @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;
 }
コード例 #15
0
 /**
  * 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));
 }
コード例 #16
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__));
     }
     $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;
 }
コード例 #17
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));
 }
コード例 #18
0
ファイル: FormBannerGlobals.php プロジェクト: gridguyz/banner
 /**
  * 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())));
 }
コード例 #19
0
 /**
  * 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;
 }
コード例 #20
0
ファイル: Renderer.php プロジェクト: Andyyang1981/pi
 /**
  * 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);
 }
コード例 #21
0
ファイル: FormSelect.php プロジェクト: haoyanfei/zf2
 /**
  * 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) && $name !== 0) {
         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 = $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));
 }
コード例 #22
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 ColumnsPercentages) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Grid\\Paragraph\\Form\\Element\\ColumnsPercentages', __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__));
     }
     $values = $element->getValue();
     if (empty($values)) {
         $values = array();
     }
     $attributes = $element->getAttributes();
     $addAttr = array('type' => 'number', 'required' => empty($attributes['required']) ? null : 'required', 'disabled' => empty($attributes['disabled']) ? null : 'disabled');
     unset($attributes['type']);
     unset($attributes['required']);
     unset($attributes['disabled']);
     return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), $this->renderPercentages($values, $name, $addAttr));
 }
コード例 #23
0
ファイル: FormSelect.php プロジェクト: nuxwin/zf2
 /**
  * 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));
 }
コード例 #24
0
ファイル: FormRow.php プロジェクト: coolms/common
 /**
  * {@inheritDoc}
  *
  * @param string $renderMode
  */
 public function __invoke(ElementInterface $element = null, $labelPosition = null, $renderErrors = null, $partial = null, $renderMode = null)
 {
     if (!$element) {
         return $this;
     }
     if (null !== $renderMode) {
         $this->setRenderMode($renderMode);
     }
     if (null === $labelPosition) {
         $labelPosition = $this->getLabelPosition();
     }
     if ($renderErrors !== null) {
         $this->setRenderErrors($renderErrors);
     }
     if (is_string($partial)) {
         $this->setPartial($partial);
     }
     if ($element->getOption(self::RENDERED) || $element->getAttribute('type') === self::RENDER_STATIC && ($this->getRenderMode() === self::RENDER_DYNAMIC || null === $element->getValue())) {
         return '';
     }
     return $this->render($element, $labelPosition, $partial);
 }
コード例 #25
0
ファイル: FormCheckboxTree.php プロジェクト: usban/entilocali
 /**
  * @param \Zend\Form\ElementInterface $element
  * @return \Zend\Form\ElementInterface $element
  */
 public function render(ElementInterface $element)
 {
     $values = $element->getValue();
     $name = $element->getAttribute('name');
     $checkedValues = $element->getOption('checked_value');
     $element = '';
     if (is_array($values)) {
         $i = 0;
         foreach ($values as $key => $value) {
             $element .= '<div class="checkbox"><label><input type="checkbox" name="' . $name . '[]" id="' . $name . '_' . $i . '" value="' . $key . '"';
             if (is_array($checkedValues)) {
                 foreach ($checkedValues as $checkedValue) {
                     if ($checkedValue['id'] == $key) {
                         $element .= ' checked';
                         continue;
                     }
                 }
             }
             $element .= '> ' . $value . '</label></div>';
             $i++;
         }
     }
     return $element;
 }
コード例 #26
0
ファイル: ToggleButton.php プロジェクト: cross-solution/yawik
 /**
  * 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)
 {
     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('');
     }
     $value = $element->getValue();
     $checkedBoole = $value == 1 || $value == 'on';
     $checkedClass = $checkedBoole ? 'active"' : '';
     $hiddenElement = '';
     if ($element->useHiddenElement()) {
         $hiddenAttributes = ['name' => $element->getName(), 'value' => $element->getUncheckedValue()];
         $hiddenElement = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), '>');
         $element->setUseHiddenElement(false);
     }
     $buttonContent = $hiddenElement . PHP_EOL . '<div class="btn-group" data-toggle="buttons">' . PHP_EOL . '<label class="btn btn-default ' . $checkedClass . '">' . PHP_EOL . parent::render($element) . $buttonContent . PHP_EOL . '</label>' . PHP_EOL . '</div>' . PHP_EOL;
     return $buttonContent;
 }
コード例 #27
0
ファイル: FormBannerLocales.php プロジェクト: gridguyz/banner
 /**
  * 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 LocaleBanners) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Grid\\Banner\\Form\\Element\\LocaleBanners', __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();
     $attributes = $element->getAttributes();
     $value = (array) $element->getValue();
     $groups = array();
     foreach ($value as $locale => $banners) {
         $label = 'locale.sub.' . $locale;
         if ($this->isTranslatorEnabled() && $this->hasTranslator()) {
             $label = $this->getTranslator()->translate($label, 'locale');
         }
         $groups[] = array('header' => $label, 'markup' => $this->renderBanners($name . '[' . $locale . ']', $banners), 'attributes' => array('data-locale' => $locale));
     }
     unset($attributes['name']);
     $attributes['data-locales'] = json_encode(array_keys(array_filter($appService('Locale')->getAvailableFlags())));
     return $this->renderBannerGroups($name . '[__locale__]', $attributes, $groups);
 }
コード例 #28
0
 /**
  * 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) {
         $partial = $element->getViewPartial();
         $summaryPartial = $partial . '.summary';
         $partialParams = array('element' => $element);
         if (!$this->getView()->resolver($summaryPartial)) {
             $summaryPartial = $partial;
             $partialParams['renderSummary'] = true;
         }
         return $this->getView()->partial($summaryPartial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         $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 = $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();
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3"><strong>' . $label . '</strong></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }
コード例 #29
0
 /**
  * @see \Zend\Form\View\Helper\AbstractHelper::render()
  * @param ElementInterface $oElement
  * @return string
  */
 public function render(ElementInterface $oElement)
 {
     return sprintf(self::$staticFormat, $oElement->getValue());
 }
コード例 #30
0
ファイル: Element.php プロジェクト: rb-cohen/jzform
 public function render(ElementInterface $element)
 {
     $elementData = array('type' => $element->getAttribute('type'), 'name' => $element->getName(), 'label' => $element->getLabel(), 'value' => $element->getValue(), 'attributes' => $this->renderAttributes($element, array('name', 'type')));
     $specData = $this->getSpec($element);
     return array_merge($elementData, $specData);
 }