Eno\Fieldset » element
element($name) → element or null
element($name, $options) → element or null
Retrieve a single entry as Field
(instead of
its direct value) from the fieldset by its name.
Optionally specify whether it's optional or mandatory for the entry to be
present in the eno document (by default it's optional).
enoyears:
2007 = Year of the gooseberry
2010 = Year of the awesome beanstalk
2011 = Year of yearning
php$fieldset = Parser::parse($input)->fieldset('years');
fieldset->element('2010'); // returns [Field name="2010" value="Year of the awesome beanstalk"]
fieldset->element('2020'); // returns null
fieldset->element('2020', [ 'enforce_element' => true ]); // throws a ValidationError
fieldset->element('2020', [ 'required' => true ]); // throws a ValidationError
Parameters
$nameThe name of the entry to fetch from the fieldset as a string.
$optionsenforce_element
Whether the element must be present in the document (true
or false
, defaults to false
)
required
Alias for enforce_element
(this exists on many methods and depending on context refers to either element or value)
Return value
An element (e.g. Field
, ListElement
, etc.) or null
.