You are here

function field_group_install in Field Group 7

Same name and namespace in other branches
  1. 7.2 field_group.install \field_group_install()

Implements of hook_install().

Because this is a new module in D7, hook_update_N() doesn't help D6 users who upgrade to run the migration path. So, we try that here as the module is being installed.

File

./field_group.install, line 133
Fieldgroup module install file.

Code

function field_group_install() {
  $groups = _field_group_install_read_groups();
  module_load_include('module', 'field_group');
  if (!empty($groups)) {
    module_load_include('module', 'ctools');
    ctools_include('export');
    foreach ($groups as $group) {
      $group = (object) $group;
      $new = new stdClass();
      $new->group_name = $group->group_name;
      $new->entity_type = 'node';
      $new->bundle = $group->type_name;
      $new->label = $group->label;
      $new->parent_name = '';
      $new->children = array();
      foreach ($group->children as $child) {
        $new->children[] = $child['field_name'];
      }

      // The form.
      $new->id = NULL;
      $new->weight = $group->weight;
      $new->mode = 'form';
      $new->format_type = 'fieldset';
      $new->format_settings = array(
        'formatter' => preg_match("/fieldset/", $group->settings['form']['style']) ? 'collapsible' : 'collapsed',
        'instance_settings' => array(),
      );
      $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode;
      ctools_export_crud_save('field_group', $new);

      // The full node.
      $new->id = NULL;
      $new->weight = $group->weight;
      $new->mode = 'default';
      $new->format_type = $group->settings['display']['full']['format'];
      $new->format_settings = array(
        'formatter' => 'collapsible',
        'instance_settings' => array(),
      );
      $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode;
      ctools_export_crud_save('field_group', $new);

      // The teaser node.
      $new->id = NULL;
      $new->weight = $group->weight;
      $new->mode = 'teaser';
      $new->format_type = $group->settings['display']['teaser']['format'];
      $new->format_settings = array(
        'formatter' => 'collapsible',
        'instance_settings' => array(),
      );
      $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode;
      ctools_export_crud_save('field_group', $new);
    }
  }

  // Set weight to 1.
  db_update('system')
    ->fields(array(
    'weight' => 1,
  ))
    ->condition('name', 'field_group')
    ->execute();
}