public mixed
getFieldAttribute
(mixed $name, mixed $attribute, mixed $default = null, mixed $group = null)
/**
* Method to get an attribute value from a field XML element. If the attribute doesn't exist or
* is null then the optional default value will be used.
*
* @param string $name The name of the form field for which to get the attribute value.
* @param string $attribute The name of the attribute for which to get a value.
* @param mixed $default The optional default value to use if no attribute value exists.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return mixed The attribute value for the field.
*
* @since 1.7.0
* @throws \UnexpectedValueException
*/
public function getFieldAttribute($name, $attribute, $default = null, $group = null)
{
// Make sure there is a valid Form XML document.
if (!$this->xml instanceof \SimpleXMLElement) {
throw new \UnexpectedValueException(sprintf('%s::%s `xml` is not an instance of SimpleXMLElement', \get_class($this), __METHOD__));
}
// Find the form field element from the definition.
$element = $this->findField($name, $group);
// If the element exists and the attribute exists for the field return the attribute value.
if ($element instanceof \SimpleXMLElement && \strlen((string) $element[$attribute])) {
return (string) $element[$attribute];
} else {
return $default;
}
}