You are here

function ds_get_fields in Display Suite 7.2

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

Get all fields.

Parameters

$entity_type: The name of the entity.

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

Return value

Collection of fields.

3 calls to ds_get_fields()
ds_extras_permission in modules/ds_extras/ds_extras.module
Implements hook_permission().
ds_field_attach_view_alter in ./ds.module
Implements hook_field_attach_view_alter().
_ds_field_ui_fields in includes/ds.field_ui.inc
Add the fields to the Field UI form.

File

./ds.module, line 300
Display Suite core functions.

Code

function ds_get_fields($entity_type, $cache = TRUE) {
  global $language;
  static $static_fields, $fields_cached = array();
  static $loaded = FALSE;

  // Load the ds file that handles ds call of hook_ds_fields_info, otherwise it
  // doesn't get loaded
  module_load_include('inc', 'ds', 'ds.ds_fields_info');

  // Get fields from cache.
  if (!$loaded) {
    $loaded = TRUE;
    if ($cache && ($cached_fields = cache_get('ds_fields:' . $language->language))) {
      $fields_cached = $static_fields = $cached_fields->data;
    }
  }
  if (!isset($static_fields[$entity_type])) {

    // Do we have them cached or not ?
    if (!isset($fields_cached[$entity_type])) {

      // Get all fields for this entity type.
      $fields = array();
      foreach (module_implements('ds_fields_info') as $module) {
        $function = $module . '_ds_fields_info';
        $all_fields = $function($entity_type);
        if (!empty($all_fields)) {
          foreach ($all_fields as $key => $field_results) {
            if ($key === $entity_type) {

              // Add module key to field definition.
              foreach ($field_results as $f => $d) {
                $field_results[$f]['module'] = $module;
              }
              $fields = array_merge($field_results, $fields);
            }
          }
        }
      }

      // Give modules a change to alter fields.
      drupal_alter('ds_fields_info', $fields, $entity_type);
      $fields_cached[$entity_type] = $fields;

      // Cache the fields.
      if ($cache) {
        cache_set('ds_fields:' . $language->language, $fields_cached, 'cache');
      }
    }
    else {
      $fields = $fields_cached[$entity_type];
    }

    // Store the fields statically.
    $static_fields[$entity_type] = $fields;
  }
  return isset($static_fields[$entity_type]) ? $static_fields[$entity_type] : array();
}