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, * Centerpiece of every data administration interface in Silverstripe,
* which returns a {@link FieldSet} suitable for a {@link Form} object. * which returns a {@link FieldSet} suitable for a {@link Form} object.
* If not overloaded, we're using {@link scaffoldFormFields()} to automatically * 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> * <example>
* klass MyCustomClass extends DataObject { * klass MyCustomClass extends DataObject {
@ -1533,7 +1534,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
* *
* public function getCMSFields() { * public function getCMSFields() {
* $fields = parent::getCMSFields(); * $fields = parent::getCMSFields();
* $fields->push(new CheckboxField('CustomProperty')); * $fields->addFieldToTab('Root.Content',new CheckboxField('CustomProperty'));
* return $fields; * return $fields;
* } * }
* } * }
@ -1541,14 +1542,34 @@ class DataObject extends ViewableData implements DataObjectInterface {
* *
* @see Good example of complex FormField building: SiteTree::getCMSFields() * @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() { public function getCMSFields() {
$fields = $this->scaffoldFormFields(); $fields = $this->scaffoldFormFields();
// If we don't have an ID, then relation fields don't work // If we don't have an ID, then relation fields don't work
if($this->ID) { if($this->ID) {
$fields = $this->addScaffoldRelationFields($fields); $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; 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 * This function is used to provide modifications to the form in the CMS
* by the decorator. * by the decorator. By default, no changes are made.
* By default, no changes are made - if you want you can overload this * Please consider using {@link updateFormFields()} to globally add
* function. * 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) { 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 * this function is used to provide modifications to the summary fields in CMS
* by the decorator * by the decorator