/** * {@inheritDoc} */ public function render(ElementInterface $element, $options = array()) { $captcha = $element->getCaptcha(); if ($captcha === null || !$captcha instanceof CaptchaAdapter) { throw new \DomainException(sprintf('%s requires that the element has a "captcha" attribute' . ' implementing Zend\\Captcha\\AdapterInterface; none found', __METHOD__)); } $helper = $captcha->getHelperName(); $renderer = $this->getView(); if (!method_exists($renderer, 'plugin')) { throw new \DomainException(sprintf('%s requires that the renderer implements plugin();' . ' it does not', __METHOD__)); } $helper = $renderer->plugin($helper); // Custom CAPTCHA view $separator = null; if (isset($options['separator'])) { $separator = $options['separator']; } elseif ($element->getOption('separator')) { $separator = $element->getOption('separator'); } if (null !== $separator) { $helper->setSeparator($separator); } $position = null; if (isset($options['captcha_position'])) { $position = $options['captcha_position']; } elseif ($element->getOption('captcha_position')) { $position = $element->getOption('captcha_position'); } if (null !== $position) { $helper->setCaptchaPosition($position); } return $helper($element); }
public function render(\Zend\Form\ElementInterface $oElement) { if ($oElement->getOption('value_only') === true && $oElement instanceof \IteratorAggregate) { foreach ($oElement->getIterator() as $oElementOrFieldset) { $oElementOrFieldset->setOption('value_only', true); if ($oElement->getOption('add_hidden')) { $oElementOrFieldset->setOption('add_hidden', true); } } } return parent::render($oElement); }
/** * Prepares the element prior to rendering * @param \Zend\Form\ElementInterface $element * @param string $formType * @param array $displayOptions * @return void */ protected function prepareElementBeforeRendering(ElementInterface $element, $formType, array $displayOptions) { $class = $element->getAttribute('class'); $class = $this->genUtil->addWords('btn', $class); if (array_key_exists('class', $displayOptions)) { $class = $this->genUtil->addWords($displayOptions['class'], $class); } if ($element->getOption('primary') && $element->getOption('primary') == true) { $class = $this->genUtil->addWords('btn-primary', $class); } $class = $this->genUtil->escapeWords($class, $this->getEscapeHtmlAttrHelper()); $element->setAttribute('class', $class); }
/** * Render * * @param \Zend\Form\ElementInterface $element * @param string $blockWrapper * @param string $inlineWrapper * @return string */ public function render(ElementInterface $element, $blockWrapper = null, $inlineWrapper = null) { $blockWrapper = $blockWrapper ?: $this->blockWrapper; $inlineWrapper = $inlineWrapper ?: $this->inlineWrapper; $html = ''; if ($inline = $element->getOption('help-inline')) { $html .= sprintf($inlineWrapper, $inline); } if ($block = $element->getOption('help-block')) { $html .= sprintf($blockWrapper, $block); } return $html; }
/** * Render element hint from the provided $element * @param ElementInterface $element * @return string */ public function render(ElementInterface $element) { $type = $element->getAttribute('type'); if (!in_array($type, $this->supportedTypes)) { return ''; } $escapeHelper = $this->getEscapeHtmlHelper(); $html = ''; //Hint if ($element->getOption('hint')) { $html = '<span class="help-inline">' . $escapeHelper($element->getOption('hint')) . '</span>'; } return $html; }
/** * Render a description from the provided $element * @param ElementInterface $element * @return string */ public function render(ElementInterface $element) { $type = $element->getAttribute('type'); if (!in_array($type, $this->supportedTypes)) { return ''; } $escapeHelper = $this->getEscapeHtmlHelper(); $html = ''; //Description if ($element->getOption('description')) { $html = '<p class="help-block">' . $escapeHelper($element->getOption('description')) . '</p>'; } return $html; }
/** * @param ElementInterface $element * @param boolean $block * * @return string */ public function __invoke(ElementInterface $element, $block = false) { $this->setElement(new HtmlElement('span')); $message = null; if (($message = $element->getOption('description-inline')) || ($message = $element->getOption('description'))) { $this->addClass('help-inline'); } elseif ($message = $element->getOption('description-block')) { $this->addClass('help-block'); } if (null === $message) { return ''; } $this->setDescription($message); return $this->render(); }
/** * @return string */ public function render(\Zend\Form\ElementInterface $oElement) { $config = $this->getConfig(); $name = $oElement->getName(); // Check whether some options have been passed via the form element // options $options = $oElement->getOption('ckeditor'); if (!empty($options) && !is_array($options)) { throw \Exception('The options should either be an array or a traversable object'); } elseif (empty($options)) { $options = array(); } $ckfinderLoaded = $this->getModuleManager()->getModule('CKFinderModule') !== null; // Because zf merges arrays instead of overwriting them in the config, // we allow a callback and use the return as the toolbar array if (array_key_exists('toolbar', $config['ckeditor_options']) && is_callable($config['ckeditor_options']['toolbar'])) { $toolbar = $config['ckeditor_options']['toolbar'](); if (is_array($toolbar)) { $config['ckeditor_options']['toolbar'] = $toolbar; } } // Merge the defaut edito options with the form element options // and turn them into json $jsonOptions = JsonFormatter::encode(array_merge($config['ckeditor_options'], $ckfinderLoaded ? $config['ckeditor_ckfinder_options'] : array(), $options), true); $loadFunctionName = $this->getTmpLoadFunctionName(); $src = $config['src']; return parent::render($oElement) . '<script type="text/javascript" language="javascript">' . "\n" . 'if(typeof window.ckEditorLoading == "undefined"){' . "\n" . 'window.ckEditorLoading = false;' . "\n" . 'window.ckEditorCallbacks = [];' . "\n" . '}' . "\n" . '(function() {' . "\n" . 'function ' . $loadFunctionName . '(){' . "\n" . 'CKEDITOR.replace("' . $name . '", ' . $jsonOptions . ');' . "\n" . '}' . "\n" . 'if(typeof CKEDITOR == "undefined"){' . "\n" . 'window.ckEditorCallbacks.push(' . $loadFunctionName . ');' . "\n" . 'if(!window.ckEditorLoading) {' . "\n" . 'window.ckEditorLoading = true;' . "\n" . 'var ckScript = document.createElement("script");' . "\n" . 'ckScript.type = "text/javascript";' . "\n" . 'ckScript.async = false;' . "\n" . 'ckScript.src = "' . $src . '";' . "\n" . 'var target = document.getElementsByTagName("script")[0];' . "\n" . 'target.parentNode.insertBefore(ckScript, target);' . "\n" . 'var ckEditorInterval = setInterval(function(){' . "\n" . 'if(typeof CKEDITOR != "undefined"){' . "\n" . 'clearInterval(ckEditorInterval);' . "\n" . 'for(var i in window.ckEditorCallbacks) window.ckEditorCallbacks[i]();' . "\n" . '}' . "\n" . '}, 100);' . "\n" . '}' . "\n" . '}' . "\n" . '})();' . "\n" . '</script>' . "\n"; }
/** * {@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); }
/** * 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)); }
/** * 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; }
public function render(ElementInterface $element) { if ($element->getOption('use-switch')) { $element->setAttribute('data-switch', '1'); } return parent::render($element); }
public function render(ElementInterface $element) { if ($element->getOption('static')) { return $this->getView()->formElementStatic($element); } return parent::render($element); }
/** * {@inheritDoc} */ public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null) { if ($element && !$element->getOption('input_group')) { return $content; } return parent::render($content, $attribs, $element, $form); }
public function render(ElementInterface $element) { $element->setAttribute('data-role', 'datepicker'); if ($element->getOption('default-today')) { $element->setAttribute('data-default-today', 'true'); } return parent::render($element); }
public function render(ElementInterface $element) { $req = ''; if ($element->getOption('required')) { $req = 'required'; } return sprintf('<tr><td>%s</td><td>%s</td> </tr>', $element->getLabel(), parent::render($element)); }
public function __invoke(ElementInterface $element, array $arguments = array()) { $notes = $element->getOption('notes'); if (!$notes) { return null; } $view = $this->getView(); return '<div class="default-form-notes">' . vsprintf($view->translate($notes), $arguments) . '</div>'; }
/** * @param ElementInterface $element * @param FormInterface $form * @return array */ protected function getDecorators(ElementInterface $element, FormInterface $form = null) { $decorators = (array) $element->getOption($this->getDecoratorNamespace()); $helper = $this->getElementHelper(); if ($helper instanceof DecoratorProviderInterface) { $decorators = array_replace_recursive($helper->getDecoratorSpecification($element, $form), $decorators); } return $decorators; }
/** * Render a collection by iterating through all fieldsets and elements * @param \Zend\Form\ElementInterface $oElement * @return string */ public function render(ElementInterface $oElement) { $oRenderer = $this->getView(); if (!method_exists($oRenderer, 'plugin')) { return ''; } $bShouldWrap = $this->shouldWrap; $sMarkup = ''; $sElementLayout = $oElement->getOption('bootstrap-layout'); if ($oElement instanceof \IteratorAggregate) { $oElementHelper = $this->getElementHelper(); $oFieldsetHelper = $this->getFieldsetHelper(); foreach ($oElement->getIterator() as $oElementOrFieldset) { $aOptions = $oElementOrFieldset->getOptions(); if ($sElementLayout && empty($aOptions['bootstrap-layout'])) { $aOptions['bootstrap-layout'] = $sElementLayout; $oElementOrFieldset->setOptions($aOptions); } if ($oElementOrFieldset instanceof \Zend\Form\FieldsetInterface) { $sMarkup .= $oFieldsetHelper($oElementOrFieldset); } elseif ($oElementOrFieldset instanceof \Zend\Form\ElementInterface) { if ($oElementOrFieldset->getOption('bootstrap-row-open')) { $sMarkup .= '<div class="row">' . PHP_EOL; } $sMarkup .= $oElementHelper($oElementOrFieldset); if ($oElementOrFieldset->getOption('bootstrap-row-close')) { $sMarkup .= '</div>' . PHP_EOL; } } } if ($oElement instanceof \Zend\Form\Element\Collection && $oElement->shouldCreateTemplate()) { $sMarkup .= $this->renderTemplate($oElement); } } if ($bShouldWrap) { if (false != ($sLabel = $oElement->getLabel())) { if (null !== ($oTranslator = $this->getTranslator())) { $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); } $sMarkup = sprintf(self::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes() ?: array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel)) . $sMarkup; } //Set form layout class if ($sElementLayout) { $sLayoutClass = 'form-' . $sElementLayout; if (false != ($sElementClass = $oElement->getAttribute('class'))) { if (!preg_match('/(\\s|^)' . preg_quote($sLayoutClass, '/') . '(\\s|$)/', $sElementClass)) { $oElement->setAttribute('class', trim($sElementClass . ' ' . $sLayoutClass)); } } else { $oElement->setAttribute('class', $sLayoutClass); } } $sMarkup = sprintf(self::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup); } return $sMarkup; }
/** * @param ElementInterface $element * @return string */ protected function getControl(ElementInterface $element) { $btnHelper = $this->getView()->plugin('btn'); $iconHelper = $this->getView()->plugin('icon'); if ($element instanceof Collection && $element->allowAdd() && $element->shouldCreateTemplate()) { return $btnHelper($iconHelper('plus'), ['class' => 'btn-success pull-right clearfix', 'onclick' => "return CmsCommon.Form.Collection.addFieldset(this, 'prepend');"]); } elseif ($element instanceof FieldsetInterface && !$element instanceof Collection && $element->getOption('allow_remove')) { return $btnHelper($iconHelper('minus'), ['class' => 'btn-danger pull-right clearfix', 'onclick' => 'return CmsCommon.Form.Collection.removeFieldset(this);']); } }
/** * @see \Zend\Form\View\Helper\FormRadio::render() * @param \Zend\Form\ElementInterface $oElement * @return string */ public function render(\Zend\Form\ElementInterface $oElement) { if ($oElement->getOption('disable-twb')) { $sSeparator = $this->separator; $this->separator = ''; $sReturn = parent::render($oElement); $this->separator = $sSeparator; return $sReturn; } return sprintf(self::$checkboxFormat, parent::render($oElement)); }
/** * @inheritdoc */ public function render(ElementInterface $element) { $renderer = $this->getView(); if (!method_exists($renderer, 'plugin')) { // Bail early if renderer is not pluggable return ''; } $markup = ''; $templateMarkup = ''; $elementHelper = $this->getElementHelper(); $fieldsetHelper = $this->getFieldsetHelper(); $wrapperClass = $element->getOption('wrapper_class'); if ($element instanceof CollectionElement && $element->shouldCreateTemplate()) { $templateMarkup = $this->renderTemplate($element); } foreach ($element->getIterator() as $elementOrFieldset) { if ($elementOrFieldset instanceof FieldsetInterface) { $markup .= $fieldsetHelper($elementOrFieldset, $this->shouldWrap()); } elseif ($elementOrFieldset instanceof ElementInterface && is_callable($elementHelper)) { $markup .= $elementHelper($elementOrFieldset); } } if ($wrapperClass) { $markup = "<div class='{$wrapperClass}'>{$markup}</div>"; } // Every collection is wrapped by a fieldset if needed if ($this->shouldWrap) { $attributes = $element->getAttributes(); unset($attributes['name']); $attributesString = count($attributes) ? ' ' . $this->createAttributesString($attributes) : ''; $label = $element->getLabel(); $legend = ''; if (!empty($label)) { if (null !== ($translator = $this->getTranslator())) { $label = $translator->translate($label, $this->getTranslatorTextDomain()); } if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) { $escapeHtmlHelper = $this->getEscapeHtmlHelper(); $label = $escapeHtmlHelper($label); } $legend = sprintf($this->labelWrapper, $label); } $markup = sprintf($this->wrapper, $markup, $legend, $templateMarkup, $attributesString); } else { $markup .= $templateMarkup; } return $markup; }
public function getValueLabel(ElementInterface $element) { $value = $element->getValue(); if ($options = $element->getOption('value_options')) { if (isset($options[$value])) { return $options[$value]; } } if (method_exists($element, 'getValueOptions')) { foreach ($element->getValueOptions() as $option) { if (isset($option['value']) && $option['value'] == $value) { return $option['label']; } } } return $value; }
/** * 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(); $size = $element->getOption('size'); if (empty($size)) { return sprintf('<textarea %s>%s</textarea>', $this->createAttributesString($attributes), $escapeHtml($content)); } return sprintf('<div class="col-lg-%s col-md-%s col-sm-%s col-xs-%s"> <textarea %s>%s</textarea> </div>', $size, $size, $size, $size, $this->createAttributesString($attributes), $escapeHtml($content)); }
/** * @see \Zend\Form\View\Helper\FormCheckbox::render() * @param \Zend\Form\ElementInterface $oElement * @throws \LogicException * @throws \InvalidArgumentException * @return string */ public function render(\Zend\Form\ElementInterface $oElement) { if ($oElement->getOption('disable-twb')) { return parent::render($oElement); } if (!$oElement instanceof \Zend\Form\Element\Checkbox) { throw new \InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__)); } if (($sName = $oElement->getName()) !== 0 && empty($sName)) { throw new \LogicException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $aAttributes = $oElement->getAttributes(); $aAttributes['name'] = $sName; $aAttributes['type'] = $this->getInputType(); $aAttributes['value'] = $oElement->getCheckedValue(); $sClosingBracket = $this->getInlineClosingBracket(); if ($oElement->isChecked()) { $aAttributes['checked'] = 'checked'; } //Render label $sLabelOpen = $sLabelClose = $sLabelContent = ''; //Render label and visible element if ($sLabelContent = $oElement->getLabel()) { if ($oTranslator = $this->getTranslator()) { $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain()); } $oLabelHelper = $this->getLabelHelper(); $sLabelOpen = $oLabelHelper->openTag($oElement->getLabelAttributes() ?: null); $sLabelClose = $oLabelHelper->closeTag(); } //Render checkbox $sElementContent = sprintf('<input %s%s', $this->createAttributesString($aAttributes), $sClosingBracket); //Add label markup if ($this->getLabelPosition($oElement) === \Zend\Form\View\Helper\FormRow::LABEL_PREPEND) { $sElementContent = $sLabelOpen . ($sLabelContent ? rtrim($sLabelContent) . ' ' : '') . $sElementContent . $sLabelClose; } else { $sElementContent = $sLabelOpen . $sElementContent . ($sLabelContent ? ' ' . ltrim($sLabelContent) : '') . $sLabelClose; } //Render hidden input if ($oElement->useHiddenElement()) { $sElementContent = sprintf('<input type="hidden" %s%s', $this->createAttributesString(array('name' => $aAttributes['name'], 'value' => $oElement->getUncheckedValue())), $sClosingBracket) . $sElementContent; } return $sElementContent; }
/** * Get all validators for a given element * * @param InputFilterInterface $inputFilter * @param ElementInterface $element * @return mixed */ public function getValidatorsForElement(InputFilterInterface $inputFilter, ElementInterface $element) { if ($element->getOption('strokerform-exclude')) { return; } // Check if we are dealing with a fieldset element if (preg_match('/^.*\\[(.*)\\]$/', $element->getName(), $matches)) { $elementName = $matches[1]; } else { $elementName = $element->getName(); } if (!$inputFilter->has($elementName)) { return; } $input = $inputFilter->get($elementName); // Make sure NotEmpty validator is added when input is required $input->isValid(); $chain = $input->getValidatorChain(); return $chain->getValidators(); }
public function __invoke(ElementInterface $collection = null, $wrap = true) { if ($collection) { if ($collection->getOption('form-inline') || $this->hasClass($collection, 'form-inline')) { foreach ($collection as $element) { $element->setOption('form-inline', true); } } elseif ($collection->getOption('form-horizontal') || $this->hasClass($collection, 'form-hotizontal')) { $labelCols = (int) $collection->getOption('label-cols') ?: 3; $inputCols = (int) $collection->getOption('input-cols') ?: 12 - $labelCols; foreach ($collection as $element) { $options = array_merge($element->getOptions(), ['form-horizontal' => true, 'label-cols' => $labelCols, 'input-cols' => $inputCols]); $element->setOptions($options); } } } if (null !== ($shouldWrap = $collection->getOption('should_wrap'))) { $wrap = $shouldWrap; } return parent::__invoke($collection, $wrap); }
/** * @param ElementInterface $element * @return string|void */ public function render(ElementInterface $element) { $twitter = $element->getOption('twitter_date'); $twitter = empty($twitter) ? array() : $twitter; $hasButton = !empty($twitter['has-button']) || !empty($twitter['has_button']); unset($twitter['has-button']); unset($twitter['has_button']); $attrs = $element->getAttributes(); if ($hasButton) { $attrsw = array('class' => 'input-append date', 'id' => 'div-' . $attrs['id']); $attrsw = Utils::arrayMergeRecursiveRight($attrsw, $twitter); $openW = '<div ' . $this->createAttributesString($attrsw) . '>'; $closeW = '<span class="add-on"><i class="icon-calendar"></i></span></div>'; } else { $attrs = Utils::arrayMergeRecursiveRight($attrs, $twitter); $element->setAttributes($attrs); $openW = ''; $closeW = ''; } return $openW . parent::render($element) . $closeW; }
/** * {@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); }
/** * Helper method for retrieving element state class name * * @param ElementInterface $element * @param FormInterface $form * @return string */ protected function getElementStateClass(ElementInterface $element, FormInterface $form) { if (!$form->hasValidated()) { return; } $class = ''; if ($element->getOption('has_error') || $this->isElementHasError($element, $form)) { $class = 'has-error'; } elseif (!$element instanceof Element\Captcha) { $value = $element->getValue(); if ($element instanceof Element\MonthSelect) { $value = trim($value, '-'); } if ($value) { $class = $form->getMessages() ? 'has-warning' : 'has-success'; } } if ($element->getOption('has_feedback')) { $class .= ($class ? ' ' : '') . 'has-feedback'; } return $class; }