You are here

function ds_build_fields_and_regions in Display Suite 6.2

Same name and namespace in other branches
  1. 6.3 includes/ds.api.inc \ds_build_fields_and_regions()
  2. 6 ds.module \ds_build_fields_and_regions()

Get fields and regions for an object.

Parameters

object $object: The object to manipulate.

string $module: The module that is requesting.

1 call to ds_build_fields_and_regions()
ds_make in ./ds.module
API function to build and render a build mode for a given object

File

./ds.module, line 340
Core functions for the Display Suite module.

Code

function ds_build_fields_and_regions(&$object, $module) {

  // API info for this module and type.
  $api_info = ds_api_info($module, $object->type);

  // See if rendering is needed later on.
  // There are two ways of excluding: global exclude on object type
  // or per build mode per object type.
  // We don't return here, because we want to add all fields on the object
  // so themers can use it in their template.
  $exclude_build_modes = variable_get($module . '_buildmodes_exclude', array());
  $object->render_by_ds = isset($exclude_build_modes[$object->type][$object->build_mode]) && $exclude_build_modes[$object->type][$object->build_mode] == TRUE || variable_get($module . '_type_' . $object->type, FALSE) == TRUE ? FALSE : TRUE;

  // Setup the object.
  $object->regions = array();
  $object->ds_fields = array();
  $object->ds_groups = array();
  $object->preprocess_fields = array();

  // Get settings for this display/build mode combination.
  $display_settings = ds_get_settings($module, $object->type, $object->build_mode);
  if (!empty($display_settings['fields'])) {

    // Get all fields and settings for this build mode (this doesnt load
    // CCK fields, only groups).
    $available_fields = ds_get_fields($module, $object->type, $object->build_mode, $api_info['extra']);

    // The node Body can sometimes be populated with other content when empty
    // @todo - we do this here so the fields populate correctly, but find
    // somewhere logical for this.
    if (isset($object->has_empty_body) && $object->has_empty_body == 1) {
      $object->body = '';
    }

    // Iterate over fields listed on the display.
    foreach ($display_settings['fields'] as $field_key => $field_defaults) {

      // Don't render fields which are set to disabled.
      $region = isset($field_defaults['region']) ? $field_defaults['region'] : DS_DEFAULT_REGION;
      if ($region != DS_DISABLED_REGION) {

        // @todo Settings per field should be retrieved from a single
        // cached function call to ds_get_settings (or similar).
        if (isset($available_fields[$field_key])) {
          $field_settings = $available_fields[$field_key];
          if (!isset($field_settings['pipeline'])) {
            $field_settings['pipeline'] = DS_RENDER_DEFAULT;
          }
        }
        else {
          $field_settings = array();
          $field_settings['pipeline'] = DS_RENDER_NON_DS;
        }
        $field_settings = array_merge($field_defaults, $field_settings);

        // Additional field properties (which should be included a normalised
        // settings function).
        $field_settings['field_type'] = isset($field_settings['type']) ? $field_settings['type'] : DS_FIELD_TYPE_NON_DS;

        // fix key collision
        $field_settings['module'] = $module;
        $field_settings['object'] =& $object;
        $field_settings['object_type'] = $api_info['object'];

        // end @todo
        // Build the field.
        $object->ds_fields[$field_key] = ds_build_field($field_key, $field_settings);

        // Process the field into a group or region as required.
        if (!empty($object->ds_fields[$field_key]['parent'])) {
          $parent = $object->ds_fields[$field_key]['parent'];
          $object->ds_groups[$parent][$field_key] = $field_settings['weight'];
        }
        else {
          $object->regions[$region][$field_key] = $field_settings['weight'];
        }
      }
    }
  }

  // Reset render_by_ds property if needed.
  if (empty($object->regions)) {
    $object->render_by_ds = FALSE;
  }
}