Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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: 5 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

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

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.

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

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.

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

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.

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

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.

return: bool
param: NodeElement $fieldnode

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

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

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.

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

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

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

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

return: string
param: string $fieldtype

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.

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

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.

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