7 field.api.php hook_field_extra_fields()

Exposes "pseudo-field" components on fieldable entities.

Field UI's "Manage fields" and "Manage display" pages let users re-order fields, but also non-field components. For nodes, these include the title, poll choices, and other elements exposed by modules through hook_form() or hook_form_alter().

Fieldable entities or modules that want to have their components supported should expose them using this hook. The user-defined settings (weight, visible) are automatically applied on rendered forms and displayed entities in a #pre_render callback added by field_attach_form() and field_attach_view().

Return value

A nested array of 'pseudo-field' elements. Each list is nested within the following keys: entity type, bundle name, context (either 'form' or 'display'). The keys are the name of the elements as appearing in the renderable array (either the entity form or the displayed entity). The value is an associative array:

  • label: The human readable name of the element.
  • description: A short description of the element contents.
  • weight: The default weight of the element.
  • edit: (optional) String containing markup (normally a link) used as the element's 'edit' operation in the administration interface. Only for 'form' context.
  • delete: (optional) String containing markup (normally a link) used as the element's 'delete' operation in the administration interface. Only for 'form' context.

See also



Related topics

5 functions implement hook_field_extra_fields()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_field_extra_fields in modules/comment/comment.module
Implements hook_field_extra_fields().
node_field_extra_fields in modules/node/node.module
Implements hook_field_extra_fields().
poll_field_extra_fields in modules/poll/poll.module
Implements hook_field_extra_fields().
taxonomy_field_extra_fields in modules/taxonomy/taxonomy.module
Implements hook_field_extra_fields().
user_field_extra_fields in modules/user/user.module
Implements hook_field_extra_fields().
1 invocation of hook_field_extra_fields()
FieldInfo::getBundleExtraFields in modules/field/field.info.class.inc
Retrieves the "extra fields" for a bundle.


modules/field/field.api.php, line 47
Hooks provided by the Field module.


function hook_field_extra_fields() {
  $extra ['node']['poll'] = array(
    'form' => array(
      'choice_wrapper' => array(
        'label' => t('Poll choices'),
        'description' => t('Poll choices'),
        'weight' => -4,
      'settings' => array(
        'label' => t('Poll settings'),
        'description' => t('Poll module settings'),
        'weight' => -3,
    'display' => array(
      'poll_view_voting' => array(
        'label' => t('Poll vote'),
        'description' => t('Poll vote'),
        'weight' => 0,
      'poll_view_results' => array(
        'label' => t('Poll results'),
        'description' => t('Poll results'),
        'weight' => 0,

  return $extra;


The documentation above says "... elements exposed by modules through hook_form() or hook_form_alter()." but why does it limit itself to forms when it also works with hook_node_view et al?

Seems to be some issues with adding pseudo-fields for the $form['options'['somefield'] type setup, see http://drupal.org/node/1488956

The following exposes account picture as a field in display management pages.

 * Implements hook_field_extra_fields().
function yourmodule_field_extra_fields() {
$extra['user']['user'] = array(
'display' => array(
'picture' => array(
'label' => t('Picture'),
'description' => t('Picture'),
'weight' => 0,

The same can be achieved in drupal 6 with

* Implementation of hook_content_extra_fields.
function MODULE_NAME_content_extra_fields() {
  $extras['custom_field'] = array(
    'label' => t('Custom field'),
    'description' => t('Custom field to be displayed in UI.'),
    'weight' => 100,
  return $extras;

Note that if you implement this hook, you'll probably also want this patch:
to prevent your new field from suddenly being enabled everywhere.

I've found a very helpful function for displaying the "pseudo-field". I'm using it in hook_entity_view() instead of hook_node_view(), but should be the same

function my_module_entity_view($entity, $type, $view_mode, $langcode) {
  // Extra fields for nodes
  if ($type == 'node' && $entity->type == 'poll') {
    $extra_fields = field_extra_fields_get_display('node', $entity->type, $view_mode);

    // Get extrafield visibility.
    if (!empty($extra_fields['poll_view_voting']) && $extra_fields['poll_view_voting']['visible'] == TRUE) {
      // Do something awesome depending on the $view_mode (I've just added a default for all view_modes)
      switch ($view_mode) {
          $entity->content['poll_view_voting'] = array(
            '#markup' => '<div class="my-class">Foo poll content</div>'

Note that if you define the default class in 'extra fields controller class' key when defining your entity, EntityDefaultExtraFieldsController include all of your properties in the Manage display tab. So if you also return the 'display' key with this hook you will get a warning message when entering to the Manage display tab:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in htmlspecialchars()

In this case you only need to return the 'form' part of the array within this hook to get your properties visible at the Manage fields tab.