Hi Gorzek,
First, the easy way to do what you want with the username is to either:
1. Implement a beforeSave() trigger that sets this value.
or
2. Implement a fieldname__default() method in your delegate class to provide a default value for the field.
Option 1:
- Code: Select all
function beforeInsert(&$record){
$record->setValue('ownerID', getUserID());
}
(Assuming you have defined a function called getUserID() that obtains the ID of the currently logged in user.
Option 2:
- Code: Select all
function ownerID__default(){
return getUserID();
}
Both examples you can use a hidden widget for.
On the larger scale, if you do want to create custom widgets (for any purpose whatsoever) there are two ways to do it.
1. A one-off solution for your application. (easy)
2. Create a reusable widget. (more complex)
For a one-off solution all you have to do is implement the fieldname_widget block for the field in question. E.g. to accomplish what you want to do with the username you could do:
- Code: Select all
function block__ownerID_widget(){
echo '<input type="hidden" value="'.getUserID().'">';
}
Creating a reusable widget is a little more complex. A simple widget can be created by simply extending HTML_QuickForm_element (see HTML/QuickForm for some custom widgets that have been created for Xataface or lib/HTML/QuickForm for examples of widgets that are distributed with HTML_QuickForm .
In order to keep the widgets decoupled from the Xataface framework (so that they can be used outside of Xataface) i have tried not to use any Xataface specific calls inside any widget definitions. However you can create a wrapper that Xataface uses to create the widget at runtime (see Dataface/FormTool for examples of these wrappers).
I hope to get some documentation on custom widgets out at some point, but for now it would be best to just look at the existing widgets and use them as a base.
Best regards
Steve