FluidTYPO3\Vhs\ViewHelpers\Form\Select\OptionViewHelper::render PHP Method

render() public method

public render ( ) : string
return string
    public function render()
    {
        if (!$this->viewHelperVariableContainer->exists(SelectViewHelper::class, 'options')) {
            throw new \RuntimeException('Options can only be added inside select tags, optionally inside optgroup tag(s) inside the select tag', 1313937196);
        }
        if (true === (bool) $this->arguments['selected']) {
            $selected = 'selected';
        } elseif (true === $this->viewHelperVariableContainer->exists(SelectViewHelper::class, 'value')) {
            $value = $this->viewHelperVariableContainer->get(SelectViewHelper::class, 'value');
            if (false === is_object($this->arguments['value']) && false === is_array($this->arguments['value'])) {
                if (true === is_array($value)) {
                    $selected = true === in_array($this->arguments['value'], $value) ? 'selected' : '';
                } else {
                    $selected = (string) $this->arguments['value'] == (string) $value ? 'selected' : '';
                }
            }
        }
        $tagContent = $this->renderChildren();
        $options = $this->viewHelperVariableContainer->get(SelectViewHelper::class, 'options');
        $options[$tagContent] = $this->arguments['value'];
        $this->viewHelperVariableContainer->addOrUpdate(SelectViewHelper::class, 'options', $options);
        if (false === empty($selected)) {
            $this->tag->addAttribute('selected', 'selected');
        } else {
            $this->tag->removeAttribute('selected');
        }
        $this->tag->setContent($tagContent);
        if (true === isset($this->arguments['value'])) {
            $this->tag->addAttribute('value', $this->arguments['value']);
        }
        return $this->tag->render();
    }