mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX #5121 Fixed cache flushing for FieldSet when removing fields - thanks paradigmincarnate! (from r100417)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105564 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
65b3bec774
commit
28f80b8da5
@ -56,6 +56,11 @@ class FieldSet extends DataObjectSet {
|
|||||||
return $this->sequentialSaveableSet;
|
return $this->sequentialSaveableSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function flushFieldsCache() {
|
||||||
|
$this->sequentialSet = null;
|
||||||
|
$this->sequentialSaveableSet = null;
|
||||||
|
}
|
||||||
|
|
||||||
protected function collateDataFields(&$list, $saveableOnly = false) {
|
protected function collateDataFields(&$list, $saveableOnly = false) {
|
||||||
foreach($this as $field) {
|
foreach($this as $field) {
|
||||||
if($field->isComposite()) $field->collateDataFields($list, $saveableOnly);
|
if($field->isComposite()) $field->collateDataFields($list, $saveableOnly);
|
||||||
@ -89,7 +94,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
*/
|
*/
|
||||||
public function addFieldToTab($tabName, $field, $insertBefore = null) {
|
public function addFieldToTab($tabName, $field, $insertBefore = null) {
|
||||||
// This is a cache that must be flushed
|
// This is a cache that must be flushed
|
||||||
$this->sequentialSet = null;
|
$this->flushFieldsCache();
|
||||||
|
|
||||||
// Find the tab
|
// Find the tab
|
||||||
$tab = $this->findOrMakeTab($tabName);
|
$tab = $this->findOrMakeTab($tabName);
|
||||||
@ -108,7 +113,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
* @param array $fields An array of {@link FormField} objects.
|
* @param array $fields An array of {@link FormField} objects.
|
||||||
*/
|
*/
|
||||||
public function addFieldsToTab($tabName, $fields) {
|
public function addFieldsToTab($tabName, $fields) {
|
||||||
$this->sequentialSet = null;
|
$this->flushFieldsCache();
|
||||||
|
|
||||||
// Find the tab
|
// Find the tab
|
||||||
$tab = $this->findOrMakeTab($tabName);
|
$tab = $this->findOrMakeTab($tabName);
|
||||||
@ -132,8 +137,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
* @param string $fieldName The name of the field
|
* @param string $fieldName The name of the field
|
||||||
*/
|
*/
|
||||||
public function removeFieldFromTab($tabName, $fieldName) {
|
public function removeFieldFromTab($tabName, $fieldName) {
|
||||||
// This is a cache that must be flushed
|
$this->flushFieldsCache();
|
||||||
$this->sequentialSet = null;
|
|
||||||
|
|
||||||
// Find the tab
|
// Find the tab
|
||||||
$tab = $this->findOrMakeTab($tabName);
|
$tab = $this->findOrMakeTab($tabName);
|
||||||
@ -147,8 +151,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
* @param array $fields A list of fields, e.g. array('Name', 'Email')
|
* @param array $fields A list of fields, e.g. array('Name', 'Email')
|
||||||
*/
|
*/
|
||||||
public function removeFieldsFromTab($tabName, $fields) {
|
public function removeFieldsFromTab($tabName, $fields) {
|
||||||
// This is a cache that must be flushed
|
$this->flushFieldsCache();
|
||||||
$this->sequentialSet = null;
|
|
||||||
|
|
||||||
// Find the tab
|
// Find the tab
|
||||||
$tab = $this->findOrMakeTab($tabName);
|
$tab = $this->findOrMakeTab($tabName);
|
||||||
@ -170,6 +173,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
if(!$fieldName) {
|
if(!$fieldName) {
|
||||||
user_error('FieldSet::removeByName() was called with a blank field name.', E_USER_WARNING);
|
user_error('FieldSet::removeByName() was called with a blank field name.', E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
$this->flushFieldsCache();
|
||||||
|
|
||||||
foreach($this->items as $i => $child) {
|
foreach($this->items as $i => $child) {
|
||||||
if(is_object($child)){
|
if(is_object($child)){
|
||||||
@ -192,7 +196,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
* FALSE field wasn't found, nothing changed
|
* FALSE field wasn't found, nothing changed
|
||||||
*/
|
*/
|
||||||
public function replaceField($fieldName, $newField) {
|
public function replaceField($fieldName, $newField) {
|
||||||
if($this->sequentialSet) $this->sequentialSet = null;
|
$this->flushFieldsCache();
|
||||||
foreach($this->items as $i => $field) {
|
foreach($this->items as $i => $field) {
|
||||||
if(is_object($field)) {
|
if(is_object($field)) {
|
||||||
if($field->Name() == $fieldName && $field->hasData()) {
|
if($field->Name() == $fieldName && $field->hasData()) {
|
||||||
@ -384,7 +388,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
* Handler method called before the FieldSet is going to be manipulated.
|
* Handler method called before the FieldSet is going to be manipulated.
|
||||||
*/
|
*/
|
||||||
protected function onBeforeInsert($item) {
|
protected function onBeforeInsert($item) {
|
||||||
if($this->sequentialSet) $this->sequentialSet = null;
|
$this->flushFieldsCache();
|
||||||
if($item->Name()) $this->rootFieldSet()->removeByName($item->Name(), true);
|
if($item->Name()) $this->rootFieldSet()->removeByName($item->Name(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +439,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
* @return FieldSet
|
* @return FieldSet
|
||||||
*/
|
*/
|
||||||
function transform($trans) {
|
function transform($trans) {
|
||||||
$this->sequentialSet = null;
|
$this->flushFieldsCache();
|
||||||
$newFields = new FieldSet();
|
$newFields = new FieldSet();
|
||||||
foreach($this as $field) {
|
foreach($this as $field) {
|
||||||
$newFields->push($field->transform($trans));
|
$newFields->push($field->transform($trans));
|
||||||
@ -509,8 +513,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
// Update our internal $this->items parameter.
|
// Update our internal $this->items parameter.
|
||||||
$this->items = $fields;
|
$this->items = $fields;
|
||||||
|
|
||||||
// Re-set an internal cache
|
$this->flushFieldsCache();
|
||||||
$this->sequentialSet = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user