You are here

public function FieldInfo::prepareExtraFields in Drupal 7

Prepares 'extra fields' for the current run-time context.

Parameters

$extra_fields: The array of extra fields, as collected in hook_field_extra_fields().

$entity_type: The entity type.

$bundle: The bundle name.

Return value

The list of extra fields completed for the current runtime context.

1 call to FieldInfo::prepareExtraFields()
FieldInfo::getBundleExtraFields in modules/field/field.info.class.inc
Retrieves the "extra fields" for a bundle.

File

modules/field/field.info.class.inc, line 649

Class

FieldInfo
Provides field and instance definitions for the current runtime environment.

Code

public function prepareExtraFields($extra_fields, $entity_type, $bundle) {
  $entity_type_info = entity_get_info($entity_type);
  $bundle_settings = field_bundle_settings($entity_type, $bundle);
  $extra_fields += array(
    'form' => array(),
    'display' => array(),
  );
  $result = array();

  // Extra fields in forms.
  foreach ($extra_fields['form'] as $name => $field_data) {
    $settings = isset($bundle_settings['extra_fields']['form'][$name]) ? $bundle_settings['extra_fields']['form'][$name] : array();
    if (isset($settings['weight'])) {
      $field_data['weight'] = $settings['weight'];
    }
    $result['form'][$name] = $field_data;
  }

  // Extra fields in displayed entities.
  $data = $extra_fields['display'];
  foreach ($extra_fields['display'] as $name => $field_data) {
    $settings = isset($bundle_settings['extra_fields']['display'][$name]) ? $bundle_settings['extra_fields']['display'][$name] : array();
    $view_modes = array_merge(array(
      'default',
    ), array_keys($entity_type_info['view modes']));
    foreach ($view_modes as $view_mode) {
      if (isset($settings[$view_mode])) {
        $field_data['display'][$view_mode] = $settings[$view_mode];
      }
      else {
        $field_data['display'][$view_mode] = array(
          'weight' => $field_data['weight'],
          'visible' => TRUE,
        );
      }
    }
    unset($field_data['weight']);
    $result['display'][$name] = $field_data;
  }
  return $result;
}