1

In the admin when click edit on Manage Fields page it shows settings for that field. Can we add a custom property (checkbox) here like the required checkbox?

For example, for a decimal field it show 'Label' textbox, 'Required field' check box, 'Help text' textarea and so on. Can I add my own checkbox or textfield to this form?

1 Answer 1

1

What you'd have to do is define your own field type in a module, then use hook_field_settings_form to set the global options for that field (or hook_instance_settings_form for a specific content type's implementation).

Here's a general guide to creating your own field in Drupal 7, but to get a handle specifics of creating a custom settings option take a look at other modules' implementations of it.

For example, Drupal Commerce makes a set of options from existing customer profiles:

function commerce_customer_field_settings_form($field, $instance, $has_data) {
$settings = $field['settings'];
$form = array();

if ($field['type'] == 'commerce_customer_profile_reference') {
  $options = array();

// Build an options array of the customer profile types.
foreach (commerce_customer_profile_type_get_name() as $type => $name) {
  $options[$type] = check_plain($name);
}

$form['profile_type'] = array(
  '#type' => 'radios', 
  '#title' => t('Customer profile type that can be referenced'), 
  '#options' => $options, 
  '#default_value' => !empty($settings['profile_type']) ? $settings['profile_type'] : 'billing', 
  '#disabled' => $has_data,
 );
}

return $form;
}

Yours sounds more simple - but the same general idea. Get the field and instance data, do something with it, make another mini form and return it so it gets rendered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.