You are here

function ds_get_fields in Display Suite 6

Same name and namespace in other branches
  1. 6.3 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.

4 calls to ds_get_fields()
ds_build_fields_and_regions in ./ds.module
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.

File

./ds.module, line 516

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 ?
    $ds_fields_cached = variable_get('ds_fields_cached', array());
    if (!isset($ds_fields_cached[$module][$type_name][$build_mode]) || $reset) {

      // Fields in code.
      $fields = array();
      foreach (module_implements('ds_fields') as $prefix) {
        $function = $prefix . '_ds_fields';
        $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]);
          }
        }
      }

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

      // If we reset, remove the old settings, otherwhise, save the new ones.
      if ($reset) {
        unset($ds_fields_cached[$module][$type_name][$build_mode]);
      }
      else {
        $ds_fields_cached[$module][$type_name][$build_mode] = $fields;
      }

      // Do we cache or not ?
      if ($cache) {
        variable_set('ds_fields_cached', $ds_fields_cached);
      }
    }
    else {
      $fields = $ds_fields_cached[$module][$type_name][$build_mode];
    }

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