class FormField
FormField is the abstract class for all form fields.
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Symfony\Component\DomCrawler\Field\FormField
Expanded class hierarchy of FormField
3 files declare their use of FormField
- BrowserKitDriver.php in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - Form.php in vendor/
symfony/ dom-crawler/ Form.php - FormFieldRegistry.php in vendor/
symfony/ dom-crawler/ FormFieldRegistry.php
File
-
vendor/
symfony/ dom-crawler/ Field/ FormField.php, line 19
Namespace
Symfony\Component\DomCrawler\FieldView source
abstract class FormField {
protected string $name;
protected string|array|null $value = null;
protected \DOMDocument $document;
protected \DOMXPath $xpath;
protected bool $disabled = false;
/**
* @param \DOMElement $node The node associated with this field
*/
public function __construct(\DOMElement $node) {
$this->name = $node->getAttribute('name');
$this->xpath = new \DOMXPath($node->ownerDocument);
$this->initialize();
}
/**
* Returns the label tag associated to the field or null if none.
*/
public function getLabel() : ?\DOMElement {
$xpath = new \DOMXPath($this->node->ownerDocument);
if ($this->node
->hasAttribute('id')) {
$labels = $xpath->query(\sprintf('descendant::label[@for="%s"]', $this->node
->getAttribute('id')));
if ($labels->length > 0) {
return $labels->item(0);
}
}
$labels = $xpath->query('ancestor::label[1]', $this->node);
return $labels->length > 0 ? $labels->item(0) : null;
}
/**
* Returns the name of the field.
*/
public function getName() : string {
return $this->name;
}
/**
* Gets the value of the field.
*/
public function getValue() : string|array|null {
return $this->value;
}
/**
* Sets the value of the field.
*/
public function setValue(?string $value) : void {
$this->value = $value ?? '';
}
/**
* Returns true if the field should be included in the submitted values.
*/
public function hasValue() : bool {
return true;
}
/**
* Check if the current field is disabled.
*/
public function isDisabled() : bool {
return $this->node
->hasAttribute('disabled');
}
/**
* Initializes the form field.
*/
protected abstract function initialize() : void;
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
FormField::$disabled | protected | property | ||
FormField::$document | protected | property | ||
FormField::$name | protected | property | ||
FormField::$value | protected | property | ||
FormField::$xpath | protected | property | ||
FormField::getLabel | public | function | Returns the label tag associated to the field or null if none. | |
FormField::getName | public | function | Returns the name of the field. | |
FormField::getValue | public | function | Gets the value of the field. | |
FormField::hasValue | public | function | Returns true if the field should be included in the submitted values. | 1 |
FormField::initialize | abstract protected | function | Initializes the form field. | 4 |
FormField::isDisabled | public | function | Check if the current field is disabled. | 1 |
FormField::setValue | public | function | Sets the value of the field. | 2 |
FormField::__construct | public | function |