function ds_get_fields in Display Suite 7
Same name and namespace in other branches
- 6.3 ds.module \ds_get_fields()
- 6 ds.module \ds_get_fields()
- 6.2 ds.module \ds_get_fields()
- 7.2 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.
2 calls to ds_get_fields()
- ds_field_attach_view_alter in ./
ds.module - Implements hook_field_attach_view_alter().
- _ds_field_ui_fields in ./
ds.field_ui.inc - Add the fields to the Field UI form.
File
- ./
ds.module, line 523 - Display Suite core functions.
Code
function ds_get_fields($entity_type, $cache = TRUE) {
global $language;
static $static_fields, $fields_cached = array();
static $loaded = FALSE;
// 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();
}