1 | <?php |
||
16 | class Option extends OpenElement |
||
17 | { |
||
18 | 5 | protected function getAllowedAttributes() |
|
19 | { |
||
20 | $optionAllowedAttributes = array( |
||
21 | 5 | '/^disabled$/i' => Attribute::BOOL, |
|
22 | '/^label$/i' => Attribute::CS_STRING, |
||
23 | '/^selected$/i' => Attribute::BOOL, |
||
24 | '/^value$/i' => Attribute::CS_STRING |
||
25 | ); |
||
26 | |||
27 | 5 | return array_merge( |
|
28 | 5 | $optionAllowedAttributes, |
|
29 | 5 | parent::getAllowedAttributes() |
|
30 | ); |
||
31 | } |
||
32 | |||
33 | 4 | protected function removeInvalidChildren(LoggerInterface $logger) |
|
34 | { |
||
35 | 4 | if ($this->hasAttribute('label')) { |
|
36 | 2 | if ($this->hasAttribute('value')) { |
|
37 | // If both the "label" and "value" attributes are present, |
||
38 | // then no content is allowed. |
||
39 | 2 | foreach ($this->children as $child) { |
|
40 | 2 | if ($child instanceof NonParticipating) { |
|
41 | 2 | continue; |
|
42 | } |
||
43 | |||
44 | 1 | $logger->debug('Removing ' . $child . '. No content allowed inside an "option" element that contains both "label" and "value" attribute.'); |
|
45 | 2 | $this->removeChild($child); |
|
46 | } |
||
47 | } else { |
||
48 | // If the "label" and not "value" attribute is present, |
||
49 | // then onyl text is allowed. |
||
50 | 2 | foreach ($this->children as $child) { |
|
51 | 2 | if ($child instanceof NonParticipating || |
|
52 | 2 | $child instanceof Text) { |
|
53 | 1 | continue; |
|
54 | } |
||
55 | |||
56 | 1 | $logger->debug('Removing ' . $child . '. Only text allowed inside an "option" element that contains only a "label" attribute.'); |
|
57 | 2 | $this->removeChild($child); |
|
58 | } |
||
59 | } |
||
60 | } else { |
||
61 | // If no "label" attribute is present, |
||
62 | // then only text is allowed. |
||
63 | 4 | foreach ($this->children as $child) { |
|
64 | 4 | if ($child instanceof NonParticipating || |
|
65 | 4 | $child instanceof Text) { |
|
66 | 4 | continue; |
|
67 | } |
||
68 | |||
69 | 1 | $logger->debug('Removing ' . $child . '. Only text allowed inside an "option" element that does not contain a "label" attribute.'); |
|
70 | 1 | $this->removeChild($child); |
|
71 | } |
||
72 | } |
||
73 | 4 | } |
|
74 | |||
75 | 5 | protected function removeInvalidSelf(LoggerInterface $logger) : bool |
|
89 | } |
||
90 |