1 field.info.inc | _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle) |
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.
Related topics
File
- core/
modules/ field/ field.info.inc, line 434 - Field Info API, providing information about available fields and field types.
Code
function _field_info_prepare_extra_fields($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;
}