This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation. |
Difference between revisions of "Custom Fields"
Line 15: | Line 15: | ||
<pre> | <pre> | ||
class contact_customfield_type extends default_customfield_type { | class contact_customfield_type extends default_customfield_type { | ||
− | |||
− | + | function format_for_display($field, &$record, $fields) { | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | if(!empty($record[$field['dataname']])) { | |
− | + | $record[$field['dataname']]='<a href="#" onclick=\'GO.linkHandlers[2].call(this,'.$this->get_id($record[$field['dataname']]).');\' title="'.$this->get_name($record[$field['dataname']]).'">'. | |
− | + | $this->get_name($record[$field['dataname']]).'</a>'; | |
− | + | } | |
+ | } | ||
+ | |||
+ | private function get_id($cf) { | ||
+ | $pos = strpos($cf,':'); | ||
+ | return substr($cf,0,$pos); | ||
+ | } | ||
+ | |||
+ | private function get_name($cf) { | ||
+ | $pos = strpos($cf,':'); | ||
+ | return substr($cf,$pos+1); | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | The format_for_display function is called when the entry should be displayed on the detail panels you see on the right-hand side of most Group-Office modules. As you can see, a record field is initialized to a string, which represents a html anchor with a link to a Group-Office JavaScript event handler. In this case, our event handler GO.linkHandlers[2] summons a panel filled with data of your Custom Field's entry. |
Revision as of 17:43, 26 February 2010
Group-Office provides the possibility to add user-defined Custom Fields. These are data entries like the built-in data entries, much like the contacts in the Addressbook module, that admins can add to the existing data entries. For example, as admin, you can create the possibility for users to select an employer associated with a contact. Group-Office has predefined Custom Field types that you can use for your modules. You can add these to your modules with the Custom Fields module.
You can also create new Custom Field types. For this, you need to work with at least four files:
- One PHP-file containing a subclass of default_customfield_type, which specifies how your Custom Field should be displayed.
- One JS file of which the purpose is to allow selection of the Custom Field's actual data entry.
- Connected to the previous file, is one CustomField.js that specifies the information needed for Custom Field type selection in the Custom Field module.
- The file containing your modules's main class for registering your Custom Field in an event listener.
Here, we will show you how to make your own Custom Field type with an example of adding a contact Custom Field to a contact record.
Subclass of default_customfield_type
The default_customfield_type class contains public functions for displaying your Custom Field data in, for example, HTML tags. It also contains a public function that allows transformation of the data before storing it in the database. The class is defined in customfields.class.inc.php, though you only need to write your own extension of the class. In our example, we wrote the following subclass:
class contact_customfield_type extends default_customfield_type { function format_for_display($field, &$record, $fields) { if(!empty($record[$field['dataname']])) { $record[$field['dataname']]='<a href="#" onclick=\'GO.linkHandlers[2].call(this,'.$this->get_id($record[$field['dataname']]).');\' title="'.$this->get_name($record[$field['dataname']]).'">'. $this->get_name($record[$field['dataname']]).'</a>'; } } private function get_id($cf) { $pos = strpos($cf,':'); return substr($cf,0,$pos); } private function get_name($cf) { $pos = strpos($cf,':'); return substr($cf,$pos+1); } }
The format_for_display function is called when the entry should be displayed on the detail panels you see on the right-hand side of most Group-Office modules. As you can see, a record field is initialized to a string, which represents a html anchor with a link to a Group-Office JavaScript event handler. In this case, our event handler GO.linkHandlers[2] summons a panel filled with data of your Custom Field's entry.