public function render()
{
$name = $this->getName();
if (true === (bool) $this->arguments['multiple']) {
$name .= '[]';
}
$this->tag->addAttribute('name', $name);
if (true === isset($this->arguments['options']) && false === empty($this->arguments['options'])) {
$options = $this->getOptions();
if (true === empty($options)) {
$options = ['' => ''];
}
$this->tag->setContent($this->renderOptionTags($options));
} else {
$this->viewHelperVariableContainer->add(SelectViewHelper::class, 'options', []);
$this->viewHelperVariableContainer->add(SelectViewHelper::class, 'value', $this->getValue());
$tagContent = $this->renderChildren();
$options = $this->viewHelperVariableContainer->get(SelectViewHelper::class, 'options');
$this->tag->setContent($tagContent);
$this->viewHelperVariableContainer->remove(SelectViewHelper::class, 'options');
if (true === $this->viewHelperVariableContainer->exists(SelectViewHelper::class, 'value')) {
$this->viewHelperVariableContainer->remove(SelectViewHelper::class, 'value');
}
}
$this->setErrorClassAttribute();
$content = '';
// register field name for token generation.
// in case it is a multi-select, we need to register the field name
// as often as there are elements in the box
if (true === (bool) $this->arguments['multiple']) {
$content .= $this->renderHiddenFieldForEmptyValue();
$length = count($options);
for ($i = 0; $i < $length; $i++) {
$this->registerFieldNameForFormTokenGeneration($name);
}
$this->tag->addAttribute('multiple', 'multiple');
} else {
$this->registerFieldNameForFormTokenGeneration($name);
$this->tag->removeAttribute('multiple');
}
$content .= $this->tag->render();
return $content;
}