Hi,
So I have a couple of DataObjects that have getCMSFields and getCMSFields_forPopup implemented on them that I am managing with ModelAdmin. This by in large works fine, however these objects are also decorated and the decorated fields don't display in either a popup version or model admin interface. The decorator is also applied to the Page class and updateCMSFields works fine in that context.
I have a work around which is as follows:
public function getCMSFields() {
$fields = new FieldSet();
// ... Add fields to FieldSet
// work around for model admin
try{ $this->updateCMSFields($fields); }catch(Exception $e){ /* do nothing */ }
return $fields;
}
This works, but it does mean that Decorator::updateCMSFields() gets called twice in the CMS context.
My question is really why is updateCMSFields not getting called in the ModelAdmin or getCMSFields_forPopup context but it is in the CMS context.
I had a look at the DataObject Class and the default getCMSFields includes this line at the end of the method:
$this->extend('updateCMSFields', $fields);
Because this method is overloaded on the child object, a bigger question is perhaps why does updateCMSFields get called at all in the CMS context?
If I use that line instead of the try catch block, then updateCMSFields gets called 6 times on the execution of the page rather than twice.
As a note it seems to make little difference how many times it gets called, the additional fields are only added once luckily.