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

Breadcrumb

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

function Form::setNode

Sets the node for the form.

Expects a 'submit' button \DOMElement and finds the corresponding form element, or the form element itself.

Throws

\LogicException If given node is not a button or input or does not have a form ancestor

Overrides Link::setNode

File

vendor/symfony/dom-crawler/Form.php, line 355

Class

Form
Form represents an HTML form.

Namespace

Symfony\Component\DomCrawler

Code

protected function setNode(\DOMElement $node) : void {
    $this->button = $node;
    if ('button' === $node->nodeName || 'input' === $node->nodeName && \in_array(strtolower($node->getAttribute('type')), [
        'submit',
        'button',
        'image',
    ])) {
        if ($node->hasAttribute('form')) {
            // if the node has the HTML5-compliant 'form' attribute, use it
            $formId = $node->getAttribute('form');
            $form = $node->ownerDocument
                ->getElementById($formId);
            if (null === $form) {
                throw new \LogicException(\sprintf('The selected node has an invalid form attribute (%s).', $formId));
            }
            $this->node = $form;
            return;
        }
        // we loop until we find a form ancestor
        do {
            if (null === ($node = $node->parentNode)) {
                throw new \LogicException('The selected node does not have a form ancestor.');
            }
        } while ('form' !== $node->nodeName);
    }
    elseif ('form' !== $node->nodeName) {
        throw new \LogicException(\sprintf('Unable to submit on a "%s" tag.', $node->nodeName));
    }
    $this->node = $node;
}
RSS feed
Powered by Drupal