Total Complexity | 6 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
8 | trait RendersOptionsTrait |
||
9 | { |
||
10 | use SelectionFieldTrait; |
||
11 | |||
12 | protected OptionsProviderInterface $selectionProvider; |
||
13 | |||
14 | /** |
||
15 | * Get the value of selectionProvider |
||
16 | * |
||
17 | * @return OptionsProviderInterface |
||
18 | */ |
||
19 | public function getSelectionProvider(): OptionsProviderInterface |
||
20 | { |
||
21 | return $this->selectionProvider; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Set the value of selectionProvider |
||
26 | * |
||
27 | * @param OptionsProviderInterface $selectionProvider |
||
28 | * |
||
29 | * @return $this |
||
30 | */ |
||
31 | public function setSelectionProvider(OptionsProviderInterface $selectionProvider) |
||
32 | { |
||
33 | $this->selectionProvider = $selectionProvider; |
||
34 | |||
35 | return $this; |
||
36 | } |
||
37 | |||
38 | protected function defineSelectionText($selection): string |
||
39 | { |
||
40 | return $this->selectionProvider->defineSelectionText($selection); |
||
41 | } |
||
42 | |||
43 | protected function renderSelection(): string |
||
44 | { |
||
45 | $html = ''; |
||
46 | |||
47 | foreach ($this->getSelectionData() as $selection) { |
||
48 | $selected = $this->isSelectionSelected($this->defineSelectionValue($selection)); |
||
49 | |||
50 | $html .= $this->createOption($selection)->setSelected($selected); |
||
51 | } |
||
52 | |||
53 | return $html; |
||
54 | } |
||
55 | |||
56 | protected function createOption($selection): Option |
||
61 | ); |
||
62 | } |
||
63 | |||
64 | abstract protected function isSelectionSelected(string $value): bool; |
||
65 | } |
||
66 |