comparison vendor/symfony/dom-crawler/Form.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 5fb285c0d0e3
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
35 * @var string 35 * @var string
36 */ 36 */
37 private $baseHref; 37 private $baseHref;
38 38
39 /** 39 /**
40 * Constructor.
41 *
42 * @param \DOMElement $node A \DOMElement instance 40 * @param \DOMElement $node A \DOMElement instance
43 * @param string $currentUri The URI of the page where the form is embedded 41 * @param string $currentUri The URI of the page where the form is embedded
44 * @param string $method The method to use for the link (if null, it defaults to the method defined by the form) 42 * @param string $method The method to use for the link (if null, it defaults to the method defined by the form)
45 * @param string $baseHref The URI of the <base> used for relative links, but not for empty action 43 * @param string $baseHref The URI of the <base> used for relative links, but not for empty action
46 * 44 *
170 foreach ($this->getFiles() as $name => $value) { 168 foreach ($this->getFiles() as $name => $value) {
171 $qs = http_build_query(array($name => $value), '', '&'); 169 $qs = http_build_query(array($name => $value), '', '&');
172 if (!empty($qs)) { 170 if (!empty($qs)) {
173 parse_str($qs, $expandedValue); 171 parse_str($qs, $expandedValue);
174 $varName = substr($name, 0, strlen(key($expandedValue))); 172 $varName = substr($name, 0, strlen(key($expandedValue)));
173
174 array_walk_recursive(
175 $expandedValue,
176 function (&$value, $key) {
177 if (ctype_digit($value) && ('size' === $key || 'error' === $key)) {
178 $value = (int) $value;
179 }
180 }
181 );
182
183 reset($expandedValue);
184
175 $values = array_replace_recursive($values, array($varName => current($expandedValue))); 185 $values = array_replace_recursive($values, array($varName => current($expandedValue)));
176 } 186 }
177 } 187 }
178 188
179 return $values; 189 return $values;
209 return $uri; 219 return $uri;
210 } 220 }
211 221
212 protected function getRawUri() 222 protected function getRawUri()
213 { 223 {
224 // If the form was created from a button rather than the form node, check for HTML5 action overrides
225 if ($this->button !== $this->node && $this->button->getAttribute('formaction')) {
226 return $this->button->getAttribute('formaction');
227 }
228
214 return $this->node->getAttribute('action'); 229 return $this->node->getAttribute('action');
215 } 230 }
216 231
217 /** 232 /**
218 * Gets the form method. 233 * Gets the form method.
225 { 240 {
226 if (null !== $this->method) { 241 if (null !== $this->method) {
227 return $this->method; 242 return $this->method;
228 } 243 }
229 244
245 // If the form was created from a button rather than the form node, check for HTML5 method override
246 if ($this->button !== $this->node && $this->button->getAttribute('formmethod')) {
247 return strtoupper($this->button->getAttribute('formmethod'));
248 }
249
230 return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET'; 250 return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET';
231 } 251 }
232 252
233 /** 253 /**
234 * Returns true if the named field exists. 254 * Returns true if the named field exists.
266 return $this->fields->get($name); 286 return $this->fields->get($name);
267 } 287 }
268 288
269 /** 289 /**
270 * Sets a named field. 290 * Sets a named field.
271 *
272 * @param FormField $field The field
273 */ 291 */
274 public function set(FormField $field) 292 public function set(FormField $field)
275 { 293 {
276 $this->fields->add($field); 294 $this->fields->add($field);
277 } 295 }
353 371
354 /** 372 /**
355 * Sets the node for the form. 373 * Sets the node for the form.
356 * 374 *
357 * Expects a 'submit' button \DOMElement and finds the corresponding form element, or the form element itself. 375 * Expects a 'submit' button \DOMElement and finds the corresponding form element, or the form element itself.
358 *
359 * @param \DOMElement $node A \DOMElement instance
360 * 376 *
361 * @throws \LogicException If given node is not a button or input or does not have a form ancestor 377 * @throws \LogicException If given node is not a button or input or does not have a form ancestor
362 */ 378 */
363 protected function setNode(\DOMElement $node) 379 protected function setNode(\DOMElement $node)
364 { 380 {
425 // find form elements corresponding to the current form 441 // find form elements corresponding to the current form
426 if ($this->node->hasAttribute('id')) { 442 if ($this->node->hasAttribute('id')) {
427 // corresponding elements are either descendants or have a matching HTML5 form attribute 443 // corresponding elements are either descendants or have a matching HTML5 form attribute
428 $formId = Crawler::xpathLiteral($this->node->getAttribute('id')); 444 $formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
429 445
430 $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId)); 446 $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)]', $formId));
431 foreach ($fieldNodes as $node) { 447 foreach ($fieldNodes as $node) {
432 $this->addField($node); 448 $this->addField($node);
433 } 449 }
434 } else { 450 } else {
435 // do the xpath query with $this->node as the context node, to only find descendant elements 451 // do the xpath query with $this->node as the context node, to only find descendant elements