/** * {@inheritDoc} */ public function remove($elementOrFieldset) { if (!parent::has($elementOrFieldset) && $elementOrFieldset === 'identity' && $this->identityElement) { $elementOrFieldset = $this->identityElement->getName(); } return parent::remove($elementOrFieldset); }
/** * {@inheritDoc} */ public function getRules(ValidatorInterface $validator, ElementInterface $element = null) { $token = $validator->getToken(); if (strpos($element->getName(), "[") !== false) { $token = preg_replace('#\\[[^\\]]+\\]$#i', "[" . $token . "]", $element->getName()); } return array('equalTo' => '[name="' . $token . '"]'); }
/** * {@inheritDoc} */ public function remove($elementOrFieldset) { if (!parent::has($elementOrFieldset)) { if ($elementOrFieldset === 'identity' && $this->identityElement) { $elementOrFieldset = $this->identityElement->getName(); } elseif ($elementOrFieldset === 'credential' && $this->credentialElement) { $elementOrFieldset = $this->credentialElement->getName(); } } return parent::remove($elementOrFieldset); }
/** * 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)); }
/** * 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; }
/** * Render a form radio-group element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof RadioGroup) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zork\\Form\\Element\\RadioGroup', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $options = $element->getValueOptions(); if (empty($options)) { if (($translator = $this->getTranslator()) !== null) { return '<i>' . $translator->translate('default.empty', 'default') . '</i>'; } else { return ''; } } if (($emptyOption = $element->getEmptyOption()) !== null) { $options = array('' => $emptyOption) + $options; } $attributes = $element->getAttributes(); $value = $element->getValue(); $additionalAttribures = array('type' => 'radio', 'name' => $name, 'required' => empty($attributes['required']) ? null : 'required'); $this->validTagAttributes = $this->validRadioGroupAttributes; return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), $this->renderRadios($options, $value, $additionalAttribures, $element->getOption('option_attribute_filters'))); }
/** * 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()); }
/** * 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); }
/** * 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; }
public function __invoke(ElementInterface $element) { $elementHelper = $this->getElementHelper(); $name = preg_replace('/[^a-z0-9_-]+/', '', $element->getName()); $result = '<div id="custom' . $name . '">' . $elementHelper($element) . '</div>'; return $result; }
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)); }
/** * 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; }
/** * 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; }
/** * 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 <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)); }
/** * 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)); }
/** * Returns the control group open tag * @param ElementInterface $element * @return string */ public function openTag(ElementInterface $element) { $class = 'controls'; $id = 'controls-' . $element->getName(); $html = sprintf('<div class="%s" id="%s">', $class, $id); return $html; }
/** * @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"; }
/** * Renders a form element label from an element * @param \Zend\Form\ElementInterface $element * @param array|null $displayOptions * @return string * @throws \Zend\Form\Exception\DomainException */ public function render(ElementInterface $element, array $displayOptions = array()) { $labelContent = $element->getLabel(); if (empty($labelContent)) { throw new DomainException(sprintf('%s: No label set in the element.', __METHOD__)); } //Translate if (null !== ($translator = $this->getTranslator())) { $labelContent = $translator->translate($labelContent, $this->getTranslatorTextDomain()); } //Escape $escaperHtml = $this->getEscapeHtmlHelper(); $labelContent = $escaperHtml($labelContent); //Label attributes $labelAttributes = $element->getLabelAttributes(); if (empty($labelAttributes)) { $labelAttributes = array(); } $labelAttributes = $this->genUtil->addWordsToArrayItem('control-label', $labelAttributes, 'class'); if (array_key_exists('required', $displayOptions) && $displayOptions['required']) { $labelAttributes = $this->genUtil->addWordsToArrayItem('required', $labelAttributes, 'class'); } if (!array_key_exists('id', $labelAttributes)) { $labelAttributes['id'] = 'label-' . $element->getName(); } $element->setLabelAttributes($labelAttributes); $formLabelHelper = $this->formLabelHelper; return $formLabelHelper($element, $labelContent); }
/** * 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; }
/** * 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; }
/** * Get the name of the form element * * @param ElementInterface $element * @return string */ static function getElementName(ElementInterface $element) { $elementName = $element->getName(); if ($element instanceof MultiCheckbox && !$element instanceof Radio) { $elementName .= '[]'; } return $elementName; }
/** * Get element name * * @param ElementInterface $element * @throws Exception\DomainException * @return string */ protected static function getName(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__)); } return $name . '[]'; }
/** * Render a date element that is composed of six selects * * @param ElementInterface $element * @throws \Zend\Form\Exception\InvalidArgumentException * @throws \Zend\Form\Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof DateTimeSelectElement) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\DateTimeSelect', __METHOD__)); } $name = $element->getName(); if ($name === null || $name === '') { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $shouldRenderDelimiters = $element->shouldRenderDelimiters(); $selectHelper = $this->getSelectElementHelper(); $pattern = $this->parsePattern($shouldRenderDelimiters); $daysOptions = $this->getDaysOptions($pattern['day']); $monthsOptions = $this->getMonthsOptions($pattern['month']); $yearOptions = $this->getYearsOptions($element->getMinYear(), $element->getMaxYear()); $hourOptions = $this->getHoursOptions($pattern['hour']); $minuteOptions = $this->getMinutesOptions($pattern['minute']); $secondOptions = $this->getSecondsOptions($pattern['second']); $dayElement = $element->getDayElement()->setValueOptions($daysOptions); $monthElement = $element->getMonthElement()->setValueOptions($monthsOptions); $yearElement = $element->getYearElement()->setValueOptions($yearOptions); $hourElement = $element->getHourElement()->setValueOptions($hourOptions); $minuteElement = $element->getMinuteElement()->setValueOptions($minuteOptions); $secondElement = $element->getSecondElement()->setValueOptions($secondOptions); if ($element->shouldCreateEmptyOption()) { $dayElement->setEmptyOption(''); $yearElement->setEmptyOption(''); $monthElement->setEmptyOption(''); $hourElement->setEmptyOption(''); $minuteElement->setEmptyOption(''); $secondElement->setEmptyOption(''); } $data = array(); $data[$pattern['day']] = $selectHelper->render($dayElement); $data[$pattern['month']] = $selectHelper->render($monthElement); $data[$pattern['year']] = $selectHelper->render($yearElement); $data[$pattern['hour']] = $selectHelper->render($hourElement); $data[$pattern['minute']] = $selectHelper->render($minuteElement); if ($element->shouldShowSeconds()) { $data[$pattern['second']] = $selectHelper->render($secondElement); } else { unset($pattern['second']); if ($shouldRenderDelimiters) { unset($pattern[4]); } } $markup = ''; foreach ($pattern as $key => $value) { // Delimiter if (is_numeric($key)) { $markup .= $value; } else { $markup .= $data[$value]; } } $markup = trim($markup); return $markup; }
/** * @inheritdoc */ public function __invoke(ElementInterface $element = null, $wrap = true) { if (!$element) { return $this; } $this->setShouldWrap($wrap); $this->setWrapper('<div class="tab-pane" id="' . str_replace(" ", "_", $element->getName()) . 'Tab" %4$s>%2$s%1$s%3$s</div>'); return $this->render($element); }
/** * @param ElementInterface $element * * @return string */ protected function renderLabel(ElementInterface $element) { $labelPlugin = $this->getView()->plugin('sxb_form_control_label'); $label = $element->getLabel(); if (null !== $label) { $label = $labelPlugin($label, $element->getName(), $element->getLabelAttributes()); } return $label; }
/** * Returns the control group open tag * @param ElementInterface $element * @return string */ public function openTag(ElementInterface $element) { $class = 'control-group'; $id = 'cgroup-' . $element->getName(); if ($element->getMessages()) { $class .= ' error'; } $html = sprintf('<div class="%s" id="%s">', $class, $id); return $html; }
/** * 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>'; }
public function getSpec(ElementInterface $element) { if ($element instanceof InputProviderInterface) { $inputFilter = new ZfInputFilter(); $inputFilter->add($element->getInputSpecification()); $inputFilterRender = new InputFilter(); $data = $inputFilterRender->render($inputFilter); return $data[$element->getName()]; } return array('filters' => array(), 'validators' => array()); }
/** * @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; }