mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8262 from open-sausages/pulls/4/falsifying-tab-evidence
MINOR removeField(s)FromTab no longer creates a tab if it doesn't exist
This commit is contained in:
commit
921b98112e
@ -299,8 +299,10 @@ class FieldList extends ArrayList
|
||||
$this->flushFieldsCache();
|
||||
|
||||
// Find the tab
|
||||
$tab = $this->findOrMakeTab($tabName);
|
||||
$tab->removeByName($fieldName);
|
||||
$tab = $this->findTab($tabName);
|
||||
if ($tab) {
|
||||
$tab->removeByName($fieldName);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -318,11 +320,12 @@ class FieldList extends ArrayList
|
||||
$this->flushFieldsCache();
|
||||
|
||||
// Find the tab
|
||||
$tab = $this->findOrMakeTab($tabName);
|
||||
|
||||
// Add the fields to the end of this set
|
||||
foreach ($fields as $field) {
|
||||
$tab->removeByName($field);
|
||||
$tab = $this->findTab($tabName);
|
||||
if ($tab) {
|
||||
// Add the fields to the end of this set
|
||||
foreach ($fields as $field) {
|
||||
$tab->removeByName($field);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -428,6 +431,28 @@ class FieldList extends ArrayList
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified tab object, if it exists
|
||||
*
|
||||
* @param string $tabName The tab to return, in the form "Tab.Subtab.Subsubtab".
|
||||
* @return Tab|null The found or null
|
||||
*/
|
||||
public function findTab($tabName)
|
||||
{
|
||||
$parts = explode('.', $tabName);
|
||||
$last_idx = count($parts) - 1;
|
||||
|
||||
$currentPointer = $this;
|
||||
|
||||
foreach ($parts as $k => $part) {
|
||||
$parentPointer = $currentPointer;
|
||||
/** @var FormField $currentPointer */
|
||||
$currentPointer = $currentPointer->fieldByName($part);
|
||||
}
|
||||
|
||||
return $currentPointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified tab object, creating it if necessary.
|
||||
*
|
||||
|
@ -247,6 +247,32 @@ class FieldListTest extends SapphireTest
|
||||
$this->assertTrue($tabbedFields->hasTabSet());
|
||||
}
|
||||
|
||||
public function testFindTab()
|
||||
{
|
||||
$fields = new FieldList(
|
||||
$root = new TabSet(
|
||||
'Root',
|
||||
$tab1 = new Tab('Tab1'),
|
||||
$tab2 = new Tab('Tab2'),
|
||||
$tab3 = new Tab('Tab3'),
|
||||
$more = new TabSet(
|
||||
'More',
|
||||
$tab4 = new Tab('Tab4')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($fields->findTab('Root'), $root);
|
||||
$this->assertNull($fields->findTab('Tab5'));
|
||||
|
||||
$this->assertNull($fields->findTab('Tab3'));
|
||||
$this->assertEquals($fields->findTab('Root.Tab3'), $tab3);
|
||||
|
||||
$this->assertNull($fields->findTab('More'));
|
||||
$this->assertEquals($fields->findTab('Root.More'), $more);
|
||||
$this->assertEquals($fields->findTab('Root.More.Tab4'), $tab4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test removing an array of fields from a tab in a set.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user