3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 185 Views |
-
removeByName not working in decorators

18 February 2013 at 9:55pm Last edited: 18 February 2013 10:09pm
Hi,
I'm using a global ArticlePage pagetype for multiple websites. I use a decorator for each site to tweak the functionality as needed.
In some of the sites, some fields are not necessary so I have to remove them. But using $fields->removeByName('NameOfField') or $fields->removeFieldFromTab('Root.Content.Main','NameOfField') on the decorator doesn't seem to work.
Is this a bug? I'm using 2.4.7.
ArticlePageDecorator extends DataObjectDecorator {
function updateCMSFields($fields){
// not working
$fields->removeByName('NameOfField');// oddly, this is working
$fields->addFieldToTab('Root.Content.Main', new TextField('TestField'));
}
}:: I also found this 2-year-old page that looks to have the same issue: http://www.silverstripe.org/dataobjectmanager-module-forum/show/15402
-
Re: removeByName not working in decorators

18 February 2013 at 10:58pm
Hi Lou,
Something similar came up on the IRC channel last week. In that case, it was because the code to call the extension is actually called before the field in question (the field to be removed) was added - it couldn't remove a field that didn't exist (yet).
The solution was, at the bottom of the getCMSFields() function in Page.php, to add:
$this->extend('updateCMSFields', $fields);
Good luck
-
Re: removeByName not working in decorators

18 February 2013 at 11:58pm Last edited: 19 February 2013 12:00am
Thanks, kinglozzer.
That did work!
| 185 Views | ||
|
Page:
1
|
Go to Top |


