function _field_extra_fields_pre_render

7.x field.module _field_extra_fields_pre_render($elements)

Pre-render callback to adjust weights and visibility of non-field elements.

Related topics

2 string references to '_field_extra_fields_pre_render'
field_attach_form in drupal-7.x/modules/field/field.attach.inc
Add form elements for all fields for an entity to a form structure.
field_attach_view in drupal-7.x/modules/field/field.attach.inc
Returns a renderable array for the fields on an entity.

File

drupal-7.x/modules/field/field.module, line 710
Attach custom data fields to Drupal entities.

Code

function _field_extra_fields_pre_render($elements) {
  $entity_type = $elements['#entity_type'];
  $bundle = $elements['#bundle'];

  if (isset($elements['#type']) && $elements['#type'] == 'form') {
    $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');
    foreach ($extra_fields as $name => $settings) {
      if (isset($elements[$name])) {
        $elements[$name]['#weight'] = $settings['weight'];
      }
    }
  }
  elseif (isset($elements['#view_mode'])) {
    $view_mode = $elements['#view_mode'];
    $extra_fields = field_extra_fields_get_display($entity_type, $bundle, $view_mode);
    foreach ($extra_fields as $name => $settings) {
      if (isset($elements[$name])) {
        $elements[$name]['#weight'] = $settings['weight'];
        // Visibility: make sure we do not accidentally show a hidden element.
        $elements[$name]['#access'] = isset($elements[$name]['#access']) ? ($elements[$name]['#access'] && $settings['visible']) : $settings['visible'];
      }
    }
  }

  return $elements;
}