/**
* Method to remove a field from the form definition.
*
* @param string $name The name of the form field for which remove.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return boolean True on success, false otherwise.
*
* @since 1.7.0
* @throws \UnexpectedValueException
*/
public function removeField($name, $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 remove it from the form definition.
if ($element instanceof \SimpleXMLElement) {
$dom = dom_import_simplexml($element);
$dom->parentNode->removeChild($dom);
return true;
}
return false;
}