/** * 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 a form <select> element from the provided $element * * @param ElementInterface $element * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof SelectElement) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $options = $element->getValueOptions(); if (($emptyOption = $element->getEmptyOption()) !== null) { $options = array('' => $emptyOption) + $options; } $attributes = $element->getAttributes(); $value = $this->validateMultiValue($element->getValue(), $attributes); $attributes['name'] = $name; if (array_key_exists('multiple', $attributes) && $attributes['multiple']) { $attributes['name'] .= '[]'; } $this->validTagAttributes = $this->validSelectAttributes; $rendered = sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value)); // Render hidden element $useHiddenElement = method_exists($element, 'useHiddenElement') && method_exists($element, 'getUnselectedValue') && $element->useHiddenElement(); if ($useHiddenElement) { $rendered = $this->renderHiddenElement($element) . $rendered; } return $rendered; }
/** * 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 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\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if ($element instanceof Radio) { $options = $element->getValueOptions(); if (empty($options)) { if (($translator = $this->getTranslator()) !== null) { return '<i>' . $translator->translate('default.empty', 'default') . '</i>'; } else { return ''; } } } return parent::render($element); }
/** * 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 MultiCheckbox) { $options = $element->getValueOptions(); if (empty($options)) { if (($translator = $this->getTranslator()) !== null) { return '<i>' . $translator->translate('default.empty', 'default') . '</i>'; } else { return ''; } } } return '<div class="multi_checkbox">' . parent::render($element) . '</div>'; }
/** * 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)); }
protected function prepareLabel(ElementInterface $element) { $escapeHtmlHelper = $this->getEscapeHtmlHelper(); $valuesOptions = $element->getValueOptions(); //append span with c-indicator for each option foreach ($valuesOptions as $key => $optionSpec) { if (is_scalar($optionSpec)) { $optionSpec = ['label' => $optionSpec, 'value' => $key]; } if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) { $optionSpec['label'] = $escapeHtmlHelper($optionSpec['label']); } $optionSpec['label'] = '<span class="c-indicator"></span>' . $optionSpec['label']; $valuesOptions[$key] = $optionSpec; } //disable escape because it was already used above $element->setLabelOption('disable_html_escape', true); $element->setValueOptions($valuesOptions); }
/** * 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) { $renderer = $this->getView(); /* @var $renderer \Zend\View\Renderer\PhpRenderer */ $origPartial = $element->getViewPartial(); $partial = "{$origPartial}.view"; $partialParams = array('element' => $element); if (!$renderer->resolver($partial)) { $partial = $origPartial; $partialParams['renderSummary'] = true; } return $renderer->partial($partial, $partialParams); } if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) { /* @var $element EmptySummaryAwareInterface|ElementInterface */ $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 = $this->getTranslator()->translate($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(); if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) { $options = $element->getValueOptions(); $translator = $this->getTranslator(); if (true == $element->getAttribute('multiple')) { $multiOptions = []; foreach ($elementValue as $optionKey) { if (isset($options[$optionKey])) { $multiOptions['__general__'][] = $translator->translate($options[$optionKey]); continue; } foreach ($options as $optKey => $optVal) { if (!is_array($optVal) || !array_key_exists($optionKey, $optVal['options'])) { continue; } $optGroupLabel = isset($optVal['label']) ? $translator->translate($optVal['label']) : $optKey; $multiOptions[$optGroupLabel][] = $translator->translate($optVal['options'][$optionKey]); } } $elementValue = []; foreach ($multiOptions as $optGroupLabel => $vals) { $elementValue[] = "<b>{$optGroupLabel}</b><br>" . join(', ', $vals); } $elementValue = join('<br>', $elementValue) . '<br>'; } else { $elementValue = $translator->translate($options[$elementValue]); } } if ('' != $elementValue && $element instanceof \Zend\Form\Element\File) { return ''; } $markup .= '<div class="row">'; $col = 12; if ($label) { $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>'; $col = 9; } $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>'; return $markup; }
public function render(ElementInterface $element) { $type = $element->getAttribute('type'); if ($type == 'multi_checkbox' || $type == "radio") { $aOptions = $element->getValueOptions(); $aAtributes = $element->getOptions(); $aClasse = $element->getAttributes(); $aClasse = explode(" ", @$aClasse["class"]); $sType = $type; $selected = $element->getValue(); $disabled = $element->getAttribute("disabled"); foreach ($aOptions as $sKey => $aOption) { if (is_scalar($aOption)) { $aOption = array('label' => " " . $aOption, 'value' => $sKey); } $aOption['label_attributes'] = array(); $classe = ""; if (!in_array("not-bootstrap", $aClasse)) { $classe = "btn btn-default "; if ($type == "multi_checkbox") { if (@in_array($sKey, $selected)) { $classe .= "active"; } } else { if ($type == "radio") { if ($sKey == $selected) { $classe .= "active"; } } } } if (in_array("not-bootstrap", $aClasse)) { $classe .= "not-bootstrap"; } if ($disabled) { $classe .= " disabled"; } if (empty($aOption['label_attributes']['class'])) { $aOption['label_attributes']['class'] = trim($classe); } elseif (!preg_match('/(\\s|^)' . preg_quote($classe) . '(\\s|$)/', $aOption['label_attributes']['class'])) { $aOption['label_attributes']['class'] .= trim(' ' . $classe); } if (isset($aAtributes['data'])) { foreach ($aAtributes['data'] as $key => $value) { $aOption['label_attributes']['data-' . $key] = $value[$sKey]; } } if ($disabled) { if ($type == "multi_checkbox") { if (@in_array($sKey, $selected)) { $aOptions[$sKey] = $aOption; } else { unset($aOptions[$sKey]); } } else { if ($type == "radio") { if ($sKey == $selected) { $aOptions[$sKey] = $aOption; } else { unset($aOptions[$sKey]); } } } } else { $aOptions[$sKey] = $aOption; } } $element->setValueOptions($aOptions); if (!in_array("not-bootstrap", $aClasse)) { return sprintf('<div><div class="btn-group" data-toggle="buttons">%s</div></div>', parent::render($element)); } else { return sprintf('<div>%s</div>', parent::render($element)); } } return parent::render($element); }
/** * 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) { $renderer = $this->getView(); /* @var $renderer \Zend\View\Renderer\PhpRenderer */ $origPartial = $element->getViewPartial(); $partial = "{$origPartial}.view"; $partialParams = array('element' => $element); if (!$renderer->resolver($partial)) { $partial = $origPartial; $partialParams['renderSummary'] = true; } return $renderer->partial($partial, $partialParams); } if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) { /* @var $element EmptySummaryAwareInterface|ElementInterface */ $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 = $this->getTranslator()->translate($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(); if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) { $options = $element->getValueOptions(); $elementValue = $this->getTranslator()->translate($options[$elementValue]); } $markup .= '<div class="row">'; $col = 12; if ($label) { $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>'; $col = 9; } $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>'; return $markup; }
public function render(\Zend\Form\ElementInterface $oElement) { if ($oElement->getOption('value_only') === true) { $escapeHtml = true; $sValue = $oElement->getValue(); if ($oElement instanceof \Zend\Form\Element\Select) { if (!is_array($sValue) && isset($oElement->getValueOptions()[$sValue])) { $sValue = $oElement->getValueOptions()[$sValue]; } elseif (is_array($sValue)) { foreach ($sValue as $key => $value) { if (isset($oElement->getValueOptions()[$value])) { $sValue[$key] = $oElement->getValueOptions()[$value]; } } } } elseif ($oElement instanceof \Zend\Form\Element\MultiCheckbox) { if ($oElement->getLabelOption('disable_html_escape')) { $escapeHtml = false; } $valueOptions = $oElement->getValueOptions(); if (!is_array($sValue)) { $sValue = array($sValue); } foreach ($sValue as $key => $value) { foreach ($valueOptions as $vOpt) { if ($vOpt['value'] == $value) { $sValue[$key] = $vOpt['label']; break; } } } } // ignore buttons if ($oElement instanceof \Zend\Form\Element\Button || $oElement instanceof \Zend\Form\Element\Submit) { return ''; } // hide passwords if ($oElement instanceof \Zend\Form\Element\Password) { $sValue = '*******'; } // hide hidden fields if ($oElement instanceof Hidden) { $sValue = ''; } if (is_array($sValue)) { $sValue = implode(', ', $sValue); } $valueHtml = $sValue; if ($escapeHtml) { $valueHtml = $this->getEscapeHtmlHelper()->__invoke($valueHtml); } if ($oElement->getOption('value_use_pre') === true) { $valueHtml = '<pre>' . $valueHtml . '</pre>'; } $hidden = ''; if ($oElement->getOption('add_hidden')) { // use default hidden element if requested $hiddenElement = new Hidden($oElement->getName()); $hiddenElement->setValue($oElement->getValue()); $hidden = $this->render($hiddenElement); } return sprintf('<div class="%s">%s</div>', 'form-value-only', $valueHtml) . $hidden; } return parent::render($oElement); }