Gc\View\Helper\FormMultiCheckbox::renderOptions PHP Method

renderOptions() protected method

Render options
protected renderOptions ( Zend\Form\Element\MultiCheckbox $element, array $options, array $selectedOptions, array $attributes ) : string
$element Zend\Form\Element\MultiCheckbox Element
$options array Options
$selectedOptions array Selected options
$attributes array Attributes
return string
    protected function renderOptions(MultiCheckboxElement $element, array $options, array $selectedOptions, array $attributes)
    {
        $escapeHtmlHelper = $this->getEscapeHtmlHelper();
        $labelHelper = $this->getLabelHelper();
        $labelClose = $labelHelper->closeTag();
        $labelPosition = $this->getLabelPosition();
        $globalLabelAttributes = $element->getLabelAttributes();
        $closingBracket = $this->getInlineClosingBracket();
        if (empty($globalLabelAttributes)) {
            $globalLabelAttributes = $this->labelAttributes;
        }
        $combinedMarkup = array();
        $count = 0;
        foreach ($options as $key => $optionSpec) {
            $count++;
            if ($count > 1 && array_key_exists('id', $attributes)) {
                unset($attributes['id']);
            }
            $value = '';
            $label = '';
            $selected = false;
            $disabled = false;
            $inputAttributes = $attributes;
            $labelAttributes = $globalLabelAttributes;
            if (is_scalar($optionSpec)) {
                $optionSpec = array('label' => $optionSpec, 'value' => $key);
            }
            if (isset($optionSpec['value'])) {
                $value = $optionSpec['value'];
            }
            if (isset($optionSpec['label'])) {
                $label = $optionSpec['label'];
            }
            if (isset($optionSpec['selected'])) {
                $selected = $optionSpec['selected'];
            }
            if (isset($optionSpec['disabled'])) {
                $disabled = $optionSpec['disabled'];
            }
            if (isset($optionSpec['label_attributes'])) {
                $labelAttributes = isset($labelAttributes) ? array_merge($labelAttributes, $optionSpec['label_attributes']) : $optionSpec['label_attributes'];
            }
            if (isset($optionSpec['attributes'])) {
                $inputAttributes = array_merge($inputAttributes, $optionSpec['attributes']);
            }
            if (in_array($value, $selectedOptions)) {
                $selected = true;
            }
            $inputAttributes['value'] = $value;
            $inputAttributes['checked'] = $selected;
            $inputAttributes['disabled'] = $disabled;
            if (empty($attributes['class']) or $attributes['class'] != 'input-checkbox') {
                $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
            } else {
                $labelAttributes['class'] = 'control-label col-lg-2';
                $inputAttributes['id'] = 'checkbox-' . uniqid();
                $input = sprintf('<span class="input-checkbox"><input %s%s<label for="%s"></label></span>', $this->createAttributesString($inputAttributes), $closingBracket, $inputAttributes['id']);
            }
            if (null !== ($translator = $this->getTranslator())) {
                $label = $translator->translate($label, $this->getTranslatorTextDomain());
            }
            $label = $escapeHtmlHelper($label);
            $labelOpen = $labelHelper->openTag($labelAttributes);
            $template = $labelOpen . '%s%s' . $labelClose;
            switch ($labelPosition) {
                case self::LABEL_PREPEND:
                    $markup = sprintf($template, $label, $input);
                    break;
                case self::LABEL_APPEND:
                default:
                    $markup = sprintf($template, $input, $label);
            }
            $combinedMarkup[] = $markup;
        }
        return implode($this->getSeparator(), $combinedMarkup);
    }
FormMultiCheckbox