Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

Form fields helper.

Copyright: 2013 David MonllaĆ³
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 382 lines (14 kb)
Included or required: 4 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: behat_field_manager  - X-Ref

Helper to interact with form fields.

get_form_field_from_label($label, RawMinkContext $context)   X-Ref
Gets an instance of the form field from it's label

param: string $label
param: RawMinkContext $context
return: behat_form_field

get_form_field(NodeElement $fieldnode, Session $session)   X-Ref
Gets an instance of the form field.

Not all the fields are part of a moodle form, in this
cases it fallsback to the generic form field. Also note
that this generic field type is using a generic setValue()
method from the Behat API, which is not always good to set
the value of form elements.

param: NodeElement $fieldnode
param: Session $session The behat browser session
return: behat_form_field

get_field_instance($type, NodeElement $fieldnode, Session $session)   X-Ref
Returns the appropiate behat_form_field according to the provided type.

It defaults to behat_form_field.

param: string $type The field type (checkbox, date_selector, text...)
param: NodeElement $fieldnode
param: Session $session The behat session
return: behat_form_field

guess_field_type(NodeElement $fieldnode, Session $session)   X-Ref
Guesses a basic field type and returns it.

This method is intended to detect HTML form fields when no
moodleform-specific elements have been detected.

param: NodeElement $fieldnode
param: Session $session
return: string|bool The field type or false.

is_moodleform_field(NodeElement $fieldnode)   X-Ref
Detects when the field is a moodleform field type.

Note that there are fields inside moodleforms that are not
moodleform element; this method can not detect this, this will
be managed by get_field_node_type, after failing to find the form
element element type.

param: NodeElement $fieldnode
return: bool

get_dom_elements_for_node(NodeElement $fieldnode, Session $session)   X-Ref
Get the DOMDocument and DOMElement for a NodeElement.

param: NodeElement $fieldnode
param: Session $session
return: array

get_field_node_type(NodeElement $fieldnode, Session $session)   X-Ref
Recursive method to find the field type.

Depending on the field the felement class node is in a level or in another. We
look recursively for a parent node with a 'felement' class to find the field type.

param: NodeElement $fieldnode The current node.
param: Session $session The behat browser session
return: null|string A text description of the node type, or null if one could not be accurately determined

get_field_type(\DOMDocument $document, \DOMElement $node, Session $session)   X-Ref
Get the field type from the specified DOMElement.

param: \DOMDocument $document
param: \DOMElement $node
param: Session $session
return: null|string

normalise_fieldtype(string $fieldtype)   X-Ref
Normalise the field type.

param: string $fieldtype
return: string

get_field(NodeElement $fieldnode, $locator, Session $session)   X-Ref
Gets an instance of the form field.

Not all the fields are part of a moodle form, in this
cases it fallsback to the generic form field. Also note
that this generic field type is using a generic setValue()
method from the Behat API, which is not always good to set
the value of form elements.

param: NodeElement $fieldnode
param: string $locator
param: Session $session The behat browser session
return: behat_form_field

get_node_type(NodeElement $fieldnode, $locator, Session $session)   X-Ref
Recursive method to find the field type.

Depending on the field the felement class node is in a level or in another. We
look recursively for a parent node with a 'felement' class to find the field type.

param: NodeElement $fieldnode The current node.
param: string $locator
param: Session $session The behat browser session
return: mixed A NodeElement if we continue looking for the element type and String or false when we are done.