hook_field_extra_fields

Versions
7
hook_field_extra_fields($bundle)

Expose "pseudo-field" components on fieldable objects.

Field UI's 'Manage fields' page lets users re-order fields, but also non-field components. For nodes, that would be title, menu settings, or other elements exposed by contributed modules through hook_form() or hook_form_alter().

Fieldable entities or contributed modules that want to have their components supported should expose them using this hook, and use field_attach_extra_weight() to retrieve the user-defined weight when inserting the component.

Parameters

$bundle The name of the bundle being considered.

Return value

An array of 'pseudo-field' components. The keys are the name of the element as it appears in the form structure. The values are arrays with the following key/value pairs:

  • label: The human readable name of the component.
  • description: A short description of the component contents.
  • weight: The default weight of the element.
  • view: (optional) The name of the element as it appears in the rendered structure, if different from the name in the form.

Code

modules/field/field.api.php, line 33

<?php
function hook_field_extra_fields($bundle) {
  $extra = array();

  if ($type = node_type_get_type($bundle)) {
    if ($type->has_title) {
      $extra['title'] = array(
        'label' => $type->title_label,
        'description' => t('Node module element.'),
        'weight' => -5,
      );
    }
    if ($bundle == 'poll' && module_exists('poll')) {
      $extra['title'] = array(
        'label' => t('Poll title'),
        'description' => t('Poll module title.'),
        'weight' => -5,
      );
      $extra['choice_wrapper'] = array(
        'label' => t('Poll choices'),
        'description' => t('Poll module choices.'),
        'weight' => -4,
      );
      $extra['settings'] = array(
        'label' => t('Poll settings'),
        'description' => t('Poll module settings.'),
        'weight' => -3,
      );
    }
  }
  return $extra;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.