Skip to content

Commit

Permalink
FIX for #4663 ensuring return values from TabSet are retained from pa…
Browse files Browse the repository at this point in the history
…rent. Removing useless override. Cleaning up documentation in TabSet and return types.
  • Loading branch information
patricknelson committed Oct 7, 2015
1 parent 89571d9 commit a71d99c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
3 changes: 3 additions & 0 deletions forms/CompositeField.php
Expand Up @@ -222,6 +222,9 @@ public function insertBefore($insertBefore, $field) {
return $ret;
}

/**
* @uses FieldList->insertAfter()
*/
public function insertAfter($insertAfter, $field) {
$ret = $this->children->insertAfter($insertAfter, $field);
$this->sequentialSet = null;
Expand Down
4 changes: 3 additions & 1 deletion forms/FieldList.php
Expand Up @@ -312,7 +312,7 @@ public function findOrMakeTab($tabName, $title = null) {
* Returns a named field.
* You can use dot syntax to get fields from child composite fields
*
* @todo Implement similiarly to dataFieldByName() to support nested sets - or merge with dataFields()
* @todo Implement similarly to dataFieldByName() to support nested sets - or merge with dataFields()
*/
public function fieldByName($name) {
$name = $this->rewriteTabPath($name);
Expand Down Expand Up @@ -356,6 +356,7 @@ public function dataFieldByName($name) {
*
* @param string $name Name of the field to insert before
* @param FormField $item The form field to insert
* @return FormField|false
*/
public function insertBefore($name, $item) {
// Backwards compatibility for order of arguments
Expand Down Expand Up @@ -385,6 +386,7 @@ public function insertBefore($name, $item) {
*
* @param string $name Name of the field to insert after
* @param FormField $item The form field to insert
* @return FormField|false
*/
public function insertAfter($name, $item) {
// Backwards compatibility for order of arguments
Expand Down
29 changes: 18 additions & 11 deletions forms/TabSet.php
Expand Up @@ -114,7 +114,10 @@ public function getAttributes() {
}

/**
* Returns the named tab
* Returns a named field.
*
* @param string $name Name of the field you want to find. Allows for dot notation.
* @return FormField|null
*/
public function fieldByName($name) {
if(strpos($name,'.') !== false) list($name, $remainder) = explode('.',$name,2);
Expand All @@ -135,6 +138,8 @@ public function fieldByName($name) {
}
}
}

return null;
}

/**
Expand All @@ -148,22 +153,24 @@ public function push(FormField $field) {
/**
* Inserts a field before a particular field in a FieldList.
*
* @param FormField $item The form field to insert
* @param string $name Name of the field to insert before
* @param string $insertBefore Name of the field to insert before
* @param FormField $field The form field to insert
* @return FormField|null
*/
public function insertBefore($insertBefore, $field) {
parent::insertBefore($insertBefore, $field);
if($field instanceof Tab) $field->setTabSet($this);
$this->sequentialSet = null;
return parent::insertBefore($insertBefore, $field);
}

/**
* Inserts a field after a particular field in a FieldList.
*
* @param string $insertAfter Name of the field to insert after
* @param FormField $field The form field to insert
* @return FormField|null
*/
public function insertAfter($insertAfter, $field) {
parent::insertAfter($insertAfter, $field);
if($field instanceof Tab) $field->setTabSet($this);
$this->sequentialSet = null;
}

public function removeByName( $tabName, $dataFieldOnly = false ) {
parent::removeByName( $tabName, $dataFieldOnly );
return parent::insertAfter($insertAfter, $field);
}
}

0 comments on commit a71d99c

Please sign in to comment.