silverstripe-cms — pull request #694 by tractorcow (2013-05-02 20:55:55+00:00)
Title: NEW Added beforeExtendingCMSFields 

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

Please see https://github.com/silverstripe/silverstripe-cms/pull/692 for the first implementation of this method, and subsequent discussion.

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
$this->beforeExtendingCMSFields(function(FieldList $fields) {
$fields->addFieldToTab('Root.Main', new TextField('Details'));
});

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

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