administrcms/form

View on GitHub
src/Field/Option.php

Summary

Maintainability
A
0 mins
Test Coverage
C
75%
<?php

namespace Administr\Form\Field;

class Option extends Field
{
    public function render(array $attributes = [], array $viewData = [])
    {
        $value = old(str_replace('[]', '', $this->name), $this->getValue());

        $this->options = array_merge($this->options, $attributes);
        $this->setOption('value', $this->getName());
        $this->setValue($this->getName());

        if($value == $this->getValue() || is_array($value) && in_array($this->getValue(), $value)) {
            $this->setOption('selected', 'selected');
        }

        return parent::render($attributes, $viewData);
    }
}