• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / forms / 20836962018

09 Jan 2026 12:35AM UTC coverage: 93.481%. Remained the same
20836962018

push

github

dg
Container::setValues() and setDefaults() accepts array|Traversable|stdClass (BC break)

3 of 4 new or added lines in 1 file covered. (75.0%)

44 existing lines in 9 files now uncovered.

2065 of 2209 relevant lines covered (93.48%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/src/Forms/Controls/MultiSelectBox.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Forms\Controls;
11

12
use Nette;
13
use function is_array;
14

15

16
/**
17
 * Select box control that allows multiple items selection.
18
 */
19
class MultiSelectBox extends MultiChoiceControl
20
{
21
        /** @var array<int|string, mixed>  option / optgroup */
22
        private array $options = [];
23

24
        /** @var array<string, mixed> */
25
        private array $optionAttributes = [];
26

27

28
        public function __construct($label = null, ?array $items = null)
1✔
29
        {
30
                parent::__construct($label, $items);
1✔
31
                $this->setOption('type', 'select');
1✔
32
        }
1✔
33

34

35
        /**
36
         * Sets options and option groups from which to choose.
37
         * @return static
38
         */
39
        public function setItems(array $items, bool $useKeys = true)
1✔
40
        {
41
                if (!$useKeys) {
1✔
42
                        $res = [];
1✔
43
                        foreach ($items as $key => $value) {
1✔
44
                                unset($items[$key]);
1✔
45
                                if (is_array($value)) {
1✔
46
                                        foreach ($value as $val) {
1✔
47
                                                $res[$key][(string) $val] = $val;
1✔
48
                                        }
49
                                } else {
50
                                        $res[(string) $value] = $value;
1✔
51
                                }
52
                        }
53

54
                        $items = $res;
1✔
55
                }
56

57
                $this->options = $items;
1✔
58
                return parent::setItems(Nette\Utils\Arrays::flatten($items, preserveKeys: true));
1✔
59
        }
60

61

62
        public function getControl(): Nette\Utils\Html
63
        {
64
                $items = [];
1✔
65
                foreach ($this->options as $key => $value) {
1✔
66
                        $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value);
1✔
67
                }
68

69
                return Nette\Forms\Helpers::createSelectBox(
1✔
70
                        $items,
1✔
71
                        [
72
                                'disabled:' => is_array($this->disabled) ? $this->disabled : null,
1✔
73
                        ] + $this->optionAttributes,
1✔
74
                        $this->value,
1✔
75
                )->addAttributes(parent::getControl()->attrs)->multiple(true);
1✔
76
        }
77

78

79
        /** @deprecated use setOptionAttribute() */
80
        public function addOptionAttributes(array $attributes): static
1✔
81
        {
82
                $this->optionAttributes = $attributes + $this->optionAttributes;
1✔
83
                return $this;
1✔
84
        }
85

86

87
        public function setOptionAttribute(string $name, mixed $value = true): static
1✔
88
        {
89
                $this->optionAttributes[$name] = $value;
1✔
90
                return $this;
1✔
91
        }
92

93

94
        /** @return array<string, mixed> */
95
        public function getOptionAttributes(): array
96
        {
UNCOV
97
                return $this->optionAttributes;
×
98
        }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc