Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dom-crawler/Field/ChoiceFormField.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 5fb285c0d0e3 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
43 * @return bool true if the field should be included in the submitted values, false otherwise | 43 * @return bool true if the field should be included in the submitted values, false otherwise |
44 */ | 44 */ |
45 public function hasValue() | 45 public function hasValue() |
46 { | 46 { |
47 // don't send a value for unchecked checkboxes | 47 // don't send a value for unchecked checkboxes |
48 if (in_array($this->type, array('checkbox', 'radio')) && null === $this->value) { | 48 if (\in_array($this->type, ['checkbox', 'radio']) && null === $this->value) { |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 return true; | 52 return true; |
53 } | 53 } |
73 } | 73 } |
74 | 74 |
75 /** | 75 /** |
76 * Sets the value of the field. | 76 * Sets the value of the field. |
77 * | 77 * |
78 * @param string $value The value of the field | 78 * @param string|array $value The value of the field |
79 */ | 79 */ |
80 public function select($value) | 80 public function select($value) |
81 { | 81 { |
82 $this->setValue($value); | 82 $this->setValue($value); |
83 } | 83 } |
124 $this->value = null; | 124 $this->value = null; |
125 } elseif ('checkbox' === $this->type && true === $value) { | 125 } elseif ('checkbox' === $this->type && true === $value) { |
126 // check | 126 // check |
127 $this->value = $this->options[0]['value']; | 127 $this->value = $this->options[0]['value']; |
128 } else { | 128 } else { |
129 if (is_array($value)) { | 129 if (\is_array($value)) { |
130 if (!$this->multiple) { | 130 if (!$this->multiple) { |
131 throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name)); | 131 throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name)); |
132 } | 132 } |
133 | 133 |
134 foreach ($value as $v) { | 134 foreach ($value as $v) { |
142 | 142 |
143 if ($this->multiple) { | 143 if ($this->multiple) { |
144 $value = (array) $value; | 144 $value = (array) $value; |
145 } | 145 } |
146 | 146 |
147 if (is_array($value)) { | 147 if (\is_array($value)) { |
148 $this->value = $value; | 148 $this->value = $value; |
149 } else { | 149 } else { |
150 parent::setValue($value); | 150 parent::setValue($value); |
151 } | 151 } |
152 } | 152 } |
209 if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) { | 209 if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) { |
210 throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $this->node->getAttribute('type'))); | 210 throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $this->node->getAttribute('type'))); |
211 } | 211 } |
212 | 212 |
213 $this->value = null; | 213 $this->value = null; |
214 $this->options = array(); | 214 $this->options = []; |
215 $this->multiple = false; | 215 $this->multiple = false; |
216 | 216 |
217 if ('input' == $this->node->nodeName) { | 217 if ('input' == $this->node->nodeName) { |
218 $this->type = strtolower($this->node->getAttribute('type')); | 218 $this->type = strtolower($this->node->getAttribute('type')); |
219 $optionValue = $this->buildOptionValue($this->node); | 219 $optionValue = $this->buildOptionValue($this->node); |
224 } | 224 } |
225 } else { | 225 } else { |
226 $this->type = 'select'; | 226 $this->type = 'select'; |
227 if ($this->node->hasAttribute('multiple')) { | 227 if ($this->node->hasAttribute('multiple')) { |
228 $this->multiple = true; | 228 $this->multiple = true; |
229 $this->value = array(); | 229 $this->value = []; |
230 $this->name = str_replace('[]', '', $this->name); | 230 $this->name = str_replace('[]', '', $this->name); |
231 } | 231 } |
232 | 232 |
233 $found = false; | 233 $found = false; |
234 foreach ($this->xpath->query('descendant::option', $this->node) as $option) { | 234 foreach ($this->xpath->query('descendant::option', $this->node) as $option) { |
259 * | 259 * |
260 * @return array | 260 * @return array |
261 */ | 261 */ |
262 private function buildOptionValue(\DOMElement $node) | 262 private function buildOptionValue(\DOMElement $node) |
263 { | 263 { |
264 $option = array(); | 264 $option = []; |
265 | 265 |
266 $defaultDefaultValue = 'select' === $this->node->nodeName ? '' : 'on'; | 266 $defaultDefaultValue = 'select' === $this->node->nodeName ? '' : 'on'; |
267 $defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue; | 267 $defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue; |
268 $option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue; | 268 $option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue; |
269 $option['disabled'] = $node->hasAttribute('disabled'); | 269 $option['disabled'] = $node->hasAttribute('disabled'); |
299 * | 299 * |
300 * @return array | 300 * @return array |
301 */ | 301 */ |
302 public function availableOptionValues() | 302 public function availableOptionValues() |
303 { | 303 { |
304 $values = array(); | 304 $values = []; |
305 | 305 |
306 foreach ($this->options as $option) { | 306 foreach ($this->options as $option) { |
307 $values[] = $option['value']; | 307 $values[] = $option['value']; |
308 } | 308 } |
309 | 309 |