Drupal investigation

InputFormField.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DomCrawler\Field;
  11. /**
  12. * InputFormField represents an input form field (an HTML input tag).
  13. *
  14. * For inputs with type of file, checkbox, or radio, there are other more
  15. * specialized classes (cf. FileFormField and ChoiceFormField).
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class InputFormField extends FormField
  20. {
  21. /**
  22. * Initializes the form field.
  23. *
  24. * @throws \LogicException When node type is incorrect
  25. */
  26. protected function initialize()
  27. {
  28. if ('input' !== $this->node->nodeName && 'button' !== $this->node->nodeName) {
  29. throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
  30. }
  31. if ('checkbox' === strtolower($this->node->getAttribute('type'))) {
  32. throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
  33. }
  34. if ('file' === strtolower($this->node->getAttribute('type'))) {
  35. throw new \LogicException('File inputs should be instances of FileFormField.');
  36. }
  37. $this->value = $this->node->getAttribute('value');
  38. }
  39. }