You are here

function field_tools_import_groups in Field tools 7

Import groups to a bundle.

Parameters

string $entity_type: The entity type of the target bundle

string $bundle_name: The name of the target bundle

array $groups: An array of groups to be imported to the target bundle, as obtained from field_tools_get_group_code().

1 call to field_tools_import_groups()
field_tools_bundle_import_form_submit in ./field_tools.admin.inc
Submit handler for the import form.

File

./field_tools.admin.inc, line 1038
Contains admin callbacks for the Field tools module.

Code

function field_tools_import_groups($entity_type, $bundle_name, $groups) {
  if (count($groups)) {
    if (!module_exists('field_group')) {
      drupal_set_message(t('Groups could not be imported because the field_group module is not installed.'));
      return;
    }
    foreach ($groups as $group_name => $group) {
      $existing_groups = field_group_read_groups(array(
        'name' => $entity_type,
        'bundle' => $bundle_name,
      ));
      if (isset($existing_groups[$entity_type][$bundle_name][$group->mode][$group_name])) {
        drupal_set_message(t('Group %group has not been added to bundle %bundle because the bundle already contains this group.', array(
          '%group' => $group_name,
          '%bundle' => $bundle_name,
        )), 'error');
        continue;
      }
      $group->identifier = $group->group_name . '|' . $entity_type . '|' . $bundle_name . '|' . $group->mode;
      $group->bundle = $bundle_name;
      $group->entity_type = $entity_type;
      if (isset($group->id)) {
        unset($group->id);
      }
      if (isset($group->export_type)) {
        unset($group->export_type);
      }
      ctools_export_crud_save('field_group', $group);
      drupal_set_message(t('Group %group has been added to bundle %bundle.', array(
        '%group' => $group_name,
        '%bundle' => $bundle_name,
      )));
    }
  }
}