You are here

function fieldgroup_save_group in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 fieldgroup.module \fieldgroup_save_group()
  2. 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_save_group()
  3. 6.2 modules/fieldgroup/fieldgroup.module \fieldgroup_save_group()
3 calls to fieldgroup_save_group()
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
fieldgroup_display_overview_form_submit in modules/fieldgroup/fieldgroup.module
fieldgroup_edit_group_submit in modules/fieldgroup/fieldgroup.module

File

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

Code

function fieldgroup_save_group($type_name, $group) {
  $groups = fieldgroup_groups($type_name);
  if (!isset($groups[$group['group_name']])) {

    // Accept group name from programmed submissions if valid.
    if (!empty($group['group_name'])) {
      $group_name = $group['group_name'];
    }
    else {

      // Otherwise, find a valid, computer-friendly name.
      $group_name = trim($group['label']);
      $group_name = drupal_strtolower($group_name);
      $group_name = str_replace(array(
        ' ',
        '-',
      ), '_', $group_name);
      $group_name = preg_replace('/[^a-z0-9_]/', '', $group_name);
      $group_name = 'group_' . $group_name;
      $group_name = substr($group_name, 0, 30);
      if (isset($groups[$group_name])) {
        $group_name_base = $group_name;
        $counter = 0;
        while (isset($groups[$group_name])) {
          $group_name = $group_name_base . '_' . $counter++;
        }
      }
    }
    db_query("INSERT INTO {" . fieldgroup_tablename() . "} (type_name, group_name, label, settings, weight)\n             VALUES ('%s', '%s', '%s', '%s', %d)", $type_name, $group_name, $group['label'], serialize($group['settings']), $group['weight']);
    cache_clear_all('fieldgroup_data', content_cache_tablename());
    return SAVED_NEW;
  }
  else {
    db_query("UPDATE {" . fieldgroup_tablename() . "} SET label = '%s', settings = '%s', weight = %d " . "WHERE type_name = '%s' AND group_name = '%s'", $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']);
    cache_clear_all('fieldgroup_data', content_cache_tablename());
    return SAVED_UPDATED;
  }
}