I would like to add a checkbox field labeled 'Keep with next' to Field Configuration of user defined form fields. When checked it should add css class to the fields' markup that allows for CSS styling to display fields side by side e.g. First name + Last name.
I thought I could do this by extending the EditableFormField class:
CustomEditableFormField.php
<?php
/**
* Represents the base class of a editable form field
* object like {@link EditableTextField}.
*
* @package userforms
*/
class CustomEditableFormField extends Extension {
function extraStatics() {
return array(
'db' => array(
"KeepWithNext" => "Boolean"
)
);
}
/**
* Implement custom field Configuration on this field. Includes such things as
* settings and options of a given editable form field
*
* @return FieldSet
*/
public function getFieldConfiguration() {
//Debug::Show($fields);
$fields = parent::getFieldConfiguration();
$extraFields = new FieldSet(
new CheckboxField($this->owner->getFieldName('KeepWithNext'), _t('CustomEditableFormField.KEEPWITHNEXT', 'Keep with next?'), $this->owner->KeepWithNext)
);
$fields->merge($extraFields);
return $fields;
}
}
And adding DataObject::add_extension('EditableFormField', 'CustomEditableFormField'); to _config.php.
However, this doesn't seem to work.
Am I doing something wrong? Should I extend each FormField individually?