silverstripe/silverstripe-cms — pull request #692 by tractorcow (2013-05-02 01:48:15+00:00)
Title: ENHANCEMENT Added beforeExtendingCMSFields

Added beforeExtendingCMSFields to provide a finer degree of control over how CMS fields are added to a page prior to, and after extensions are added.

Modules such as Blog use disableCMSFieldsExtensions / enableCMSFieldsExtensions around field manipulation code in order to delay extension of CMS fields. See https://github.com/silverstripe/silverstripe-blog/blob/master/code/BlogEntry.php#L62

This code simply formalises it, adds test cases, and documentation. Hopefully this will make user code that performs such manipulation a bit more explicit and readable.

E.g.

```php

public function getCMSFields() {

// Before updateCMSFields we want to add some text fields, perhaps
// to be later interacted with with modules such as Translatable
$fields = $this->beforeExtendingCMSFields(get_parent_class(), function(FieldList &$fields) {
$fields->addFieldToTab('Root.Main', new TextField('Details'));
});

// after extending updateCMSFields we may want to interact with fields
// added by extensions.
$fields->removeByName('GoogleAnalytics');
return $fields;
}
```

Resolves ticket at https://github.com/silverstripe/sapphire/issues/1362