public function FieldInfo::prepareExtraFields

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 drupal/core/modules/field/lib/Drupal/field/FieldInfo.php
Retrieves the "extra fields" for a bundle.

File

drupal/core/modules/field/lib/Drupal/field/FieldInfo.php, line 530

Class

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

Namespace

Drupal\field

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' => isset($field_data['visible']) ? $field_data['visible'] : TRUE,
        );
      }
    }
    unset($field_data['weight']);
    unset($field_data['visible']);
    $result['display'][$name] = $field_data;
  }
  return $result;
}