You are here

function og_node_import_defaults in Node import 6

Implementation of hook_node_import_defaults().

File

supported/og/og.inc, line 137
Support file for the og (Organic Groups) module.

Code

function og_node_import_defaults($type, $defaults, $fields, $map) {
  $form = array();
  if (($node_type = node_import_type_is_node($type)) !== FALSE) {
    if (og_is_group_type($node_type)) {
      $form['og_selective'] = array(
        '#type' => 'radios',
        '#title' => t('Membership requests'),
        '#options' => og_selective_map(),
        '#default_value' => isset($defaults['og_selective']) ? $defaults['og_selective'] : OG_OPEN,
      );
      $form['og_register'] = array(
        '#type' => 'radios',
        '#title' => t('Registration form'),
        '#options' => array(
          0 => t('No'),
          1 => t('Yes'),
        ),
      );
      $visibility = variable_get('og_visibility_registration', OG_REGISTRATION_CHOOSE_FALSE);
      if (user_access('administer nodes')) {
        $visibility = in_array($visibility, array(
          OG_REGISTRATION_NEVER,
          OG_REGISTRATION_CHOOSE_FALSE,
        )) ? OG_REGISTRATION_CHOOSE_FALSE : OG_REGISTRATION_CHOOSE_TRUE;
      }
      $default = 0;
      switch ($visibility) {
        case OG_REGISTRATION_ALWAYS:
          $default = 1;

        // fall through
        case OG_REGISTRATION_NEVER:
          $form['og_register']['#access'] = FALSE;
          break;
        case OG_REGISTRATION_CHOOSE_TRUE:
          $default = 1;

        // fall through
        case OG_REGISTRATION_CHOOSE_FALSE:
          break;
      }
      $form['og_register']['#default_value'] = isset($defaults['og_register']) ? $defaults['og_register'] : $default;
      $form['og_directory'] = array(
        '#type' => 'radios',
        '#title' => t('List in groups directory'),
        '#options' => array(
          0 => t('No'),
          1 => t('Yes'),
        ),
      );
      $visibility = variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_TRUE);
      if (user_access('administer nodes')) {
        $visibility = in_array($visibility, array(
          OG_DIRECTORY_NEVER,
          OG_DIRECTORY_CHOOSE_FALSE,
        )) ? OG_DIRECTORY_CHOOSE_FALSE : OG_DIRECTORY_CHOOSE_TRUE;
      }
      $default = 0;
      switch ($visibility) {
        case OG_DIRECTORY_ALWAYS:
          $default = 1;

        // fall through
        case OG_DIRECTORY_NEVER:
          $form['og_directory']['#access'] = FALSE;
          break;
        case OG_DIRECTORY_CHOOSE_TRUE:
          $default = 1;

        // fall through
        case OG_DIRECTORY_CHOOSE_FALSE:
          break;
      }
      $form['og_directory']['#default_value'] = isset($defaults['og_directory']) ? $defaults['og_directory'] : $default;
    }
    if (og_is_group_post_type($node_type)) {
      $groups = _node_import_og_groups();
      if (!empty($groups)) {
        $form['og_groups'] = array(
          '#title' => t('Audience'),
          '#type' => count($groups, COUNT_RECURSIVE) > 20 ? 'select' : 'checkboxes',
          '#options' => $groups,
          '#multiple' => TRUE,
          '#default_value' => isset($defaults['og_groups']) ? $defaults['og_groups'] : array(),
        );
      }
    }
  }
  return $form;
}