Neos\FluidAdaptor\ViewHelpers\Form\CheckboxViewHelper::render PHP Method

render() public method

Renders the checkbox.
public render ( boolean $checked = null, boolean $multiple = null ) : string
$checked boolean Specifies that the input element should be preselected
$multiple boolean Specifies whether this checkbox belongs to a multivalue (is part of a checkbox group)
return string
    public function render($checked = null, $multiple = null)
    {
        $this->tag->addAttribute('type', 'checkbox');
        $valueAttribute = $this->getValueAttribute(true);
        $propertyValue = null;
        if ($this->hasMappingErrorOccurred()) {
            $propertyValue = $this->getLastSubmittedFormData();
        }
        if ($checked === null && $propertyValue === null) {
            $propertyValue = $this->getPropertyValue();
        }
        if ($propertyValue instanceof \Traversable) {
            $propertyValue = iterator_to_array($propertyValue);
        }
        if (is_array($propertyValue)) {
            if ($checked === null) {
                $checked = in_array($valueAttribute, $propertyValue, true);
            }
            $this->arguments['multiple'] = true;
        } elseif (!$multiple && $propertyValue !== null) {
            $checked = (bool) $propertyValue === (bool) $valueAttribute;
        }
        $nameAttribute = $this->getName();
        if (isset($this->arguments['multiple']) && $this->arguments['multiple'] === true) {
            $nameAttribute .= '[]';
        }
        $this->registerFieldNameForFormTokenGeneration($nameAttribute);
        $this->tag->addAttribute('name', $nameAttribute);
        $this->tag->addAttribute('value', $valueAttribute);
        if ($checked === true) {
            $this->tag->addAttribute('checked', 'checked');
        }
        $this->addAdditionalIdentityPropertiesIfNeeded();
        $this->setErrorClassAttribute();
        $this->renderHiddenFieldForEmptyValue();
        return $this->tag->render();
    }

Usage Example

 /**
  * @test
  */
 public function renderCallsSetErrorClassAttribute()
 {
     $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
     $this->viewHelper->render();
 }