function 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 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

array 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.
  • visible: (optional) The default visibility of the element. Only for 'display' context. Defaults to TRUE.
  • 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

hook_field_extra_fields_alter()

Related topics

8 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 drupal/core/modules/comment/comment.module
Implements hook_field_extra_fields().
contact_field_extra_fields in drupal/core/modules/contact/contact.module
Implements hook_field_extra_fields().
entity_test_field_extra_fields in drupal/core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_field_extra_fields().
node_field_extra_fields in drupal/core/modules/node/node.module
Implements hook_field_extra_fields().
overlay_field_extra_fields in drupal/core/modules/overlay/overlay.module
Implements hook_field_extra_fields().

... See full list

1 invocation of hook_field_extra_fields()
FieldInfo::getBundleExtraFields in drupal/core/modules/field/lib/Drupal/field/FieldInfo.php
Retrieves the "extra fields" for a bundle.

File

drupal/core/modules/field/field.api.php, line 44

Code

function hook_field_extra_fields() {
  $extra = array();
  $module_language_enabled = module_exists('language');
  $description = t('Node module element');
  foreach (node_type_get_types() as $bundle) {
    if ($bundle->has_title) {
      $extra['node'][$bundle->type]['form']['title'] = array(
        'label' => $bundle->title_label,
        'description' => $description,
        'weight' => -5,
      );
    }

    // Add also the 'language' select if Language module is enabled and the
    // bundle has multilingual support.
    // Visibility of the ordering of the language selector is the same as on the
    // node/add form.
    if ($module_language_enabled) {
      $configuration = language_get_default_configuration('node', $bundle->type);
      if ($configuration['language_show']) {
        $extra['node'][$bundle->type]['form']['language'] = array(
          'label' => t('Language'),
          'description' => $description,
          'weight' => 0,
        );
      }
    }
    $extra['node'][$bundle->type]['display']['language'] = array(
      'label' => t('Language'),
      'description' => $description,
      'weight' => 0,
      'visible' => FALSE,
    );
  }
  return $extra;
}