FEATURE Added DataObject->getFormFields() - uses DataObject->scaffoldFormFields() by default. Added DataObjectDecorator->updateFormFields() for easy customization

ENHANCEMENT Calling DataObjectDecorator->updateCMSFields() in DataObject->getCMSFields() - was previously only called in SiteTree instances

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63623 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-10-03 16:21:09 +00:00
parent e5d4bf6216
commit 02ae284e10
2 changed files with 43 additions and 7 deletions

View File

@ -1525,7 +1525,8 @@ class DataObject extends ViewableData implements DataObjectInterface {
* Centerpiece of every data administration interface in Silverstripe,
* which returns a {@link FieldSet} suitable for a {@link Form} object.
* If not overloaded, we're using {@link scaffoldFormFields()} to automatically
* generate this set.
* generate this set. To customize, overload this method in a subclass
* or decorate onto it by using {@link DataObjectDecorator->updateCMSFields()}.
*
* <example>
* klass MyCustomClass extends DataObject {
@ -1533,7 +1534,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
*
* public function getCMSFields() {
* $fields = parent::getCMSFields();
* $fields->push(new CheckboxField('CustomProperty'));
* $fields->addFieldToTab('Root.Content',new CheckboxField('CustomProperty'));
* return $fields;
* }
* }
@ -1541,14 +1542,34 @@ class DataObject extends ViewableData implements DataObjectInterface {
*
* @see Good example of complex FormField building: SiteTree::getCMSFields()
*
* @return FieldSet
* @return FieldSet Returns a TabSet for usage within the CMS - don't use for frontend forms.
*/
public function getCMSFields() {
$fields = $this->scaffoldFormFields();
// If we don't have an ID, then relation fields don't work
if($this->ID) {
$fields = $this->addScaffoldRelationFields($fields);
}
$this->extend('updateCMSFields', $fields);
return $fields;
}
/**
* Used for simple frontend forms without relation editing
* or {@link TabSet} behaviour. Uses {@link scaffoldFormFields()}
* by default. To customize, either overload this method in your
* subclass, or decorate it by {@link DataObjectDecorator->updateFormFields()}.
*
* @return FieldSet Always returns a simple field collection without TabSet.
*/
public function getFormFields() {
$fields = $this->scaffoldFormFields();
$this->extend('updateFormFields', $fields);
return $fields;
}

View File

@ -99,15 +99,30 @@ abstract class DataObjectDecorator extends Extension {
/**
* This function is used to provide modifications to the form in the CMS
* by the decorator.
* By default, no changes are made - if you want you can overload this
* function.
* by the decorator. By default, no changes are made.
* Please consider using {@link updateFormFields()} to globally add
* formfields to the record. The method {@link updateCMSFields()}
* should just be used to add or modify tabs, or fields which
* are specific to the CMS-context.
*
* @param FieldSet $fields The FieldSet to modify.
* Caution: Use {@link FieldSet->addFieldToTab()} to add fields.
*
* @param FieldSet $fields FieldSet with a contained TabSet
*/
function updateCMSFields(FieldSet &$fields) {
}
/**
* This function is used to provide modifications to the form in the CMS
* by the decorator.
*
* Caution: Use {@link FieldSet->push()} to add fields.
*
* @param FieldSet $fields FieldSet without TabSet nesting
*/
function updateFormFields(FieldSet &$fields) {
}
/**
* this function is used to provide modifications to the summary fields in CMS
* by the decorator