Jump to:
| Project: | Content Construction Kit (CCK) |
| Version: | 6.x-2.5 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
There's a few modules I use that haven't integrated with the drag-&-drop interface in CCK (i.e. you can't specify the weight of these module's fields).
I'd like to submit patches for these modules, but the documentation regarding how this is done seems incomplete or hard to understand. Could someone please explain to me exactly how this is done, or point me to where this is well explained?
The main things I'm having trouble with are:
- What other functions to implement other than 'hook_content_extra_fields()' (which itself is not really explained anywhere)
- Whether the weight component of 'hook_content_extra_fields()' should be static or dynamic
- If dynamic, how to properly use 'content_extra_field_weight()'
- Whether 'content_extra_field_weight()' should be used anywhere else in the module
Any and all help would be much appreciated!
Comments
#1
CCK already provides support for all non-CCK elements added by Drupal modules to the node edit form. This is implemented by content_content_extra_fields() in content.module
This function is invoked by CCK from _content_type_info() in content.module as a module hook, hook_content_extra_fields($type_name), where $type_name is the machine readable name of a content type.
All contrib/custom modules that add top level elements to the node edit form need to implement hook_content_extra_fields() in order to allow CCK manage their weights from the "Manage fields" screen. If this hook is not implemented, the elements provided by these modules may end up at any position when CCK is enabled. This is because there's no way to know the range of weights that result from drag'n'drop operations in the "Manage fields" screen.
And this hook is all these modules need to implement to make this work. The return value of this hook should be a named array where keys are the names of the elements in the form. Please, see content_content_extra_fields() for examples.
Related issue that may worth reading: #409144: content_extra_weights gets corrupted and breaks the ordering of form elements on node edit form
#2
So say I want to enable moduleX to integrate with CCK, is this all I need to add to it?
<?phpfunction modulex_content_extra_fields($type_name) {
$fields['module_x'] = array(
'label' => t('ModuleX'),
'description' => t('ModuleX module form.'),
'weight' => 0,
);
return $fields;
}
?>
What should the value of 'weight' be?
#3
#4
Yes. In your example, 'module_x' should be the name of the top level element added to the node edit form.
#5
and 'weight' should be the default weight modulex assigns to the element when CCK is not enabled.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.