You are here

function fieldgroup_groups in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 5 fieldgroup.module \fieldgroup_groups()
  2. 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_groups()
  3. 6 modules/fieldgroup/fieldgroup.module \fieldgroup_groups()

Returns all groups for a content type

19 calls to fieldgroup_groups()
ContentUICrud::testAddFieldUI in tests/content.crud.test
content_copy_export_form in modules/content_copy/content_copy.module
A form to export field definitions.
content_copy_import_form_submit in modules/content_copy/content_copy.module
Submit handler for import form. For each submitted field: 1) add new field to the database 2) execute the imported field macro to update the settings to the imported values
content_display_overview_form in includes/content.admin.inc
Menu callback; presents a listing of fields display settings for a content type.
content_field_overview_form in includes/content.admin.inc
Menu callback; listing of fields for a content type.

... See full list

File

modules/fieldgroup/fieldgroup.module, line 220
Create field groups for CCK fields.

Code

function fieldgroup_groups($content_type = '', $sorted = FALSE, $reset = FALSE) {
  global $language;
  static $groups, $groups_sorted;
  if (!isset($groups) || $reset) {
    if ($cached = cache_get('fieldgroup_data:' . $language->language, content_cache_tablename())) {
      $data = $cached->data;
      $groups = $data['groups'];
      $groups_sorted = $data['groups_sorted'];
    }
    else {
      $result = db_query("SELECT * FROM {" . fieldgroup_tablename() . "} ORDER BY weight, group_name");
      $groups = array();
      $groups_sorted = array();
      while ($group = db_fetch_array($result)) {
        $group['settings'] = unserialize($group['settings']);
        $group['fields'] = array();

        // Allow external modules to translate field group strings.
        $group_strings = array(
          'label' => $group['label'],
          'form_description' => $group['settings']['form']['description'],
          'display_description' => $group['settings']['display']['description'],
        );
        drupal_alter('content_fieldgroup_strings', $group_strings, $group['type_name'], $group['group_name']);
        $group['label'] = $group_strings['label'];
        $group['settings']['form']['description'] = $group_strings['form_description'];
        $group['settings']['display']['description'] = $group_strings['display_description'];
        $groups[$group['type_name']][$group['group_name']] = $group;
        $groups_sorted[$group['type_name']][] =& $groups[$group['type_name']][$group['group_name']];
      }

      //load fields
      $result = db_query("SELECT nfi.*, ng.group_name FROM {" . fieldgroup_tablename() . "} ng " . "INNER JOIN {" . fieldgroup_fields_tablename() . "} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name " . "INNER JOIN {" . content_instance_tablename() . "} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name " . "WHERE nfi.widget_active = 1 ORDER BY nfi.weight");
      while ($field = db_fetch_array($result)) {

        // Allow external modules to translate field strings.
        $field_strings = array(
          'widget_label' => $field['label'],
          'widget_description' => $field['description'],
        );
        drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']);
        $field['label'] = $field_strings['widget_label'];
        $field['description'] = $field_strings['widget_description'];
        $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field;
      }
      cache_set('fieldgroup_data:' . $language->language, array(
        'groups' => $groups,
        'groups_sorted' => $groups_sorted,
      ), content_cache_tablename());
    }
  }
  if (empty($content_type)) {
    return $groups;
  }
  elseif (empty($groups) || empty($groups[$content_type])) {
    return array();
  }
  return $sorted ? $groups_sorted[$content_type] : $groups[$content_type];
}