Hi,

I'm working with Content Profile and trying to add an additional global setting for when you create a new field under the Profile content type (like maximum length is. Let's call it 'priority'). I'm wondering what the best way would be for a module to add the setting to fields, instead of having to create new field types and using hook_field_settings.

Thanks

Comments

eaton’s picture

Not really. Those settings, and their data, are maintained individually by the modules handling the fields. You could hook_form_alter() the settings form, and carefully only alter the forms that "matter" for what you're doing... then hook_form_alter() in some additional validation/checking code when the real node form is built.

Beyond that, though, there's no real way to change the underlying behavior of a whole range of CCK fields.

mefi represent!

--
Eaton — Partner at Autogram

vickey’s picture

Hello All,

I got the solution for Drupal 6. hook_form_alter is used to add the form api field into cck general settings, as follows :

function example_form_alter(&$form, $form_state, $form_id){
	if($form_id == "content_field_edit_form"){
		$form['field']['test'] = array(
			'#type' => 'select',
			'#title' => t('Test'),
			'#options' => array(NULL, 1, 2, 3, 4, 5, 6, 7),
			'#weight' => 0,
			'#default_value' => $form['fields']['test'],
			'#description' => t('Test')
		);
	}
}

If you want to store the field value in cck table then you will refer some funcitons like hook_schema_alter, db_add_field, db_drop_alter, we need to put these functions in modulename.install file. sample code as follows

function example_install() {
    drupal_load('module', 'content');
    db_add_field($ret, 'content_node_field', 'test', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
}

function example_schema_alter(&$schema) {
  $schema['content_node_field']['fields']['test'] = array('type' => 'int', 'not null' => FALSE, 'default' => NULL);
}