Add support for removing form fields

This commit is contained in:
flynsarmy 2015-02-07 19:52:34 +10:00
parent 99fc380aa3
commit 5805ddec5a
2 changed files with 41 additions and 0 deletions

View File

@ -84,6 +84,26 @@ class FormTabs implements IteratorAggregate, ArrayAccess
}
}
/**
* Remove a field from all tabs by name.
* @param string $name
* @return True on success, False on failure
*/
public function removeField($name)
{
foreach ($this->fields as $tab => $fields) {
foreach ($fields as $fieldName => $field) {
if ($fieldName == $name) {
unset($this->fields[$tab][$fieldName]);
return true;
}
}
}
return false;
}
/**
* Add a field to the collection of tabs.
* @param string $name

View File

@ -459,6 +459,27 @@ class Form extends WidgetBase
}
}
/**
* Programatically remove a field.
* @return True on success, False on failure
*/
public function removeField($name)
{
if (!isset($this->fields[$name])) {
return false;
}
// Remove from tabs
$this->primaryTabs->removeField($name);
$this->secondaryTabs->removeField($name);
$this->outsideTabs->removeField($name);
// Remove from form
unset($this->fields[$name]);
return true;
}
/**
* Programatically add fields, used internally and for extensibility.
*/