| Conditions | 4 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | 12 | public function render(FieldViewInterface $view, array $attributes): string |
|
| 25 | { |
||
| 26 | 12 | if (!$choices = $view->choices()) { |
|
| 27 | 1 | throw new InvalidArgumentException('Choices must be provided for render a select element.'); |
|
| 28 | } |
||
| 29 | |||
| 30 | 11 | $attributes['name'] = $view->name(); |
|
| 31 | 11 | $attributes['required'] = $view->required(); |
|
| 32 | |||
| 33 | 11 | if (!empty($attributes['multiple'])) { |
|
| 34 | 2 | $attributes['name'] .= '[]'; |
|
| 35 | } |
||
| 36 | |||
| 37 | 11 | $options = ''; |
|
| 38 | |||
| 39 | 11 | foreach ($choices as $choice) { |
|
| 40 | 11 | $options .= HtmlRenderer::element('option', ['value' => $choice->value(), 'selected' => $choice->selected()], htmlentities($choice->label())); |
|
| 41 | } |
||
| 42 | |||
| 43 | 11 | return HtmlRenderer::element('select', $attributes, $options); |
|
| 44 | } |
||
| 60 |