Merge pull request #934 from Flynsarmy/removeFormField

Add support for removing form fields
This commit is contained in:
Samuel Georges 2015-02-12 08:32:03 +11:00
commit 77d0d25f64
2 changed files with 41 additions and 0 deletions

View File

@ -83,6 +83,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.
*/