Solution to CCK Field Groups not appearing in hook_form_alter()
One issue that I recently came across with a module I was editing was that the fieldsets / field groups from a CCK type weren't in the $form array passed to hook_form_alter().
According to Andy Chase, In CCK for D5 & D6, the 'fieldgroup' module supplied with CCK is given a weight of '9', which means that it's hooks will be run after most other modules.
Because of this, fieldgroup's hook_form_alter() function which adds the groups to the $form array is added long after your custom module's hook_form_alter() is run.
The reason for this (according to #292338: Fieldgroup module weight) is that putting them in groups makes it difficult for users to find / work with the fields. Personally, I prefer working with the groups, and, in this particular case, I needed the ability to modify the fieldsets within hook_form_alter().
The solution which Andy gave work perfectly. Create the following snippet in your mymodule.install:
<?php
/**
* Fix module weight to be heavier than CCK field group module,
* so hook_form_alter() has access to field groups
*/
function my_module_update_1() {
$items = array();
$items[] = update_sql(
"UPDATE {system}
SET weight = 10
WHERE `name` = 'my_module';"
);
drupal_set_message('Updated custom module weight.');
return $items;
}
?>
Comments
Post new comment