ENHANCEMENT: Allow chain-ability on adding and removing fields

This commit is contained in:
zanderwar 2017-11-01 14:24:21 +13:00
parent 326f74ebe6
commit 91f1a58018

View File

@ -132,6 +132,8 @@ class FieldList extends ArrayList
* or TabSet.Tab.Subtab. This function will create any missing tabs. * or TabSet.Tab.Subtab. This function will create any missing tabs.
* @param FormField $field The {@link FormField} object to add to the end of that tab. * @param FormField $field The {@link FormField} object to add to the end of that tab.
* @param string $insertBefore The name of the field to insert before. Optional. * @param string $insertBefore The name of the field to insert before. Optional.
*
* @return $this
*/ */
public function addFieldToTab($tabName, $field, $insertBefore = null) public function addFieldToTab($tabName, $field, $insertBefore = null)
{ {
@ -147,6 +149,8 @@ class FieldList extends ArrayList
} else { } else {
$tab->push($field); $tab->push($field);
} }
return $this;
} }
/** /**
@ -158,6 +162,8 @@ class FieldList extends ArrayList
* This function will create any missing tabs. * This function will create any missing tabs.
* @param array $fields An array of {@link FormField} objects. * @param array $fields An array of {@link FormField} objects.
* @param string $insertBefore Name of field to insert before * @param string $insertBefore Name of field to insert before
*
* @return $this
*/ */
public function addFieldsToTab($tabName, $fields, $insertBefore = null) public function addFieldsToTab($tabName, $fields, $insertBefore = null)
{ {
@ -178,6 +184,8 @@ class FieldList extends ArrayList
$tab->push($field); $tab->push($field);
} }
} }
return $this;
} }
/** /**
@ -185,6 +193,8 @@ class FieldList extends ArrayList
* *
* @param string $tabName The name of the tab * @param string $tabName The name of the tab
* @param string $fieldName The name of the field * @param string $fieldName The name of the field
*
* @return $this
*/ */
public function removeFieldFromTab($tabName, $fieldName) public function removeFieldFromTab($tabName, $fieldName)
{ {
@ -193,6 +203,8 @@ class FieldList extends ArrayList
// Find the tab // Find the tab
$tab = $this->findOrMakeTab($tabName); $tab = $this->findOrMakeTab($tabName);
$tab->removeByName($fieldName); $tab->removeByName($fieldName);
return $this;
} }
/** /**
@ -200,6 +212,8 @@ class FieldList extends ArrayList
* *
* @param string $tabName The name of the Tab or TabSet field * @param string $tabName The name of the Tab or TabSet field
* @param array $fields A list of fields, e.g. array('Name', 'Email') * @param array $fields A list of fields, e.g. array('Name', 'Email')
*
* @return $this
*/ */
public function removeFieldsFromTab($tabName, $fields) public function removeFieldsFromTab($tabName, $fields)
{ {
@ -212,6 +226,8 @@ class FieldList extends ArrayList
foreach ($fields as $field) { foreach ($fields as $field) {
$tab->removeByName($field); $tab->removeByName($field);
} }
return $this;
} }
/** /**
@ -222,6 +238,8 @@ class FieldList extends ArrayList
* @param boolean $dataFieldOnly If this is true, then a field will only * @param boolean $dataFieldOnly If this is true, then a field will only
* be removed if it's a data field. Dataless fields, such as tabs, will * be removed if it's a data field. Dataless fields, such as tabs, will
* be left as-is. * be left as-is.
*
* @return $this
*/ */
public function removeByName($fieldName, $dataFieldOnly = false) public function removeByName($fieldName, $dataFieldOnly = false)
{ {
@ -251,6 +269,8 @@ class FieldList extends ArrayList
$child->removeByName($fieldName, $dataFieldOnly); $child->removeByName($fieldName, $dataFieldOnly);
} }
} }
return $this;
} }
/** /**