function FormField::getLabel
Returns the label tag associated to the field or null if none.
File
-
vendor/
symfony/ dom-crawler/ Field/ FormField.php, line 42
Class
- FormField
- FormField is the abstract class for all form fields.
Namespace
Symfony\Component\DomCrawler\FieldCode
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;
}