Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FormField.php

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\Field

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal