You are here

function ds_get_fields in Display Suite 6.3

Same name and namespace in other branches
  1. 6 ds.module \ds_get_fields()
  2. 6.2 ds.module \ds_get_fields()
  3. 7.2 ds.module \ds_get_fields()
  4. 7 ds.module \ds_get_fields()

API function to get fields.

Parameters

string $module The name of the module.:

string $type_name The name of object (ie, page or story for node types, profile for users):

string $build_mode The build mode.:

array $extra Extra properties we might want to check on (ie has_body property).:

boolean $reset Whether we need to reset the fields cache or not.:

boolean $cache Whether we need to cache the fields or not.:

Return value

array of fields.

7 calls to ds_get_fields()
dsDisplay::prepare in includes/dsDisplay.php
Build field and region information
ds_build_fields_and_regions in includes/ds.api.inc
Get fields and regions for an object.
ds_display_overview_form_submit in includes/ds.display.inc
Save fields & plugins for a build mode.
ds_fields in includes/ds.fields.inc
Fields overview.
ds_fields_display_form in includes/ds.display.inc
Add fields to display overview form.

... See full list

File

./ds.module, line 512

Code

function ds_get_fields($module, $type_name, $build_mode, $extra = array(), $reset = FALSE, $cache = TRUE) {
  static $static_fields = array();
  if (!isset($static_fields[$module][$type_name][$build_mode])) {

    // Do we have them cached or not ?
    $settings = ds_get_settings($module, $type_name, $build_mode, 'fields');
    if (!isset($settings) || empty($settings) || $reset) {

      // Fields in code.
      $fields = array();
      foreach (module_implements('ds_fields') as $prefix) {
        $function = $prefix . '_ds_fields';
        if (function_exists($function)) {
          $all_fields = $function($type_name, $build_mode, $extra);
          if (!empty($all_fields)) {
            foreach ($all_fields as $key => $field_results) {
              if ($key === $module) {
                $fields = array_merge($field_results, $fields);
                foreach ($fields as $key => $field) {
                  $exclude = isset($field['exclude'][$type_name]) && $field['exclude'][$type_name] === $type_name ? TRUE : FALSE;
                  if ($exclude) {
                    unset($fields[$key]);
                  }
                }
              }
            }
          }
        }
      }

      // Fields via the UI.
      $db_fields = variable_get($module . '_fields', array());
      if (!empty($db_fields)) {
        foreach ($db_fields as $key => $field) {
          $fields[$key] = array(
            'title' => check_plain($field['title']),
            'type' => $field['type'],
            'status' => $field['status'],
            'properties' => $field['properties'],
          );
          $exclude = isset($field['exclude'][$type_name]) && $field['exclude'][$type_name] === $type_name ? TRUE : FALSE;
          if ($exclude) {
            unset($fields[$key]);
          }
        }
      }

      // Do not save the CCK fields.
      if ($cache) {
        foreach ($fields as $field_key => $field_value) {
          if (isset($field_value['storage'])) {
            unset($fields[$field_key]);
          }
        }
      }

      // Give modules a change to alter the fields.
      drupal_alter('ds_fields', $fields);

      // Do we cache or not ?
      if ($cache) {
        db_query("UPDATE {ds_settings} set fields = '%s' WHERE module = '%s' AND type = '%s' AND build_mode = '%s'", serialize($fields), $module, $type_name, $build_mode);
      }
    }
    else {
      $fields = $settings;
    }

    // Store the fields.
    $static_fields[$module][$type_name][$build_mode] = $fields;
  }
  return $static_fields[$module][$type_name][$build_mode];
}