--- 1961296-og-selection-handler-42.patch	2013-04-24 05:16:57.000000000 -0400
+++ 1961296-og-selection-handler-43.patch	2013-04-24 16:22:02.000000000 -0400
@@ -1,12 +1,11 @@
 diff --git a/commons_groups.features.field_base.inc b/commons_groups.features.field_base.inc
-index cd8b2c0..d3b99f5 100644
+index cd8b2c0..93e541d 100644
 --- a/commons_groups.features.field_base.inc
 +++ b/commons_groups.features.field_base.inc
-@@ -10,6 +10,121 @@
+@@ -10,6 +10,120 @@
  function commons_groups_field_default_field_bases() {
    $field_bases = array();
  
-+  if (module_exists('og_access')) {
 +    // Exported field_base: 'group_access'
 +    $field_bases['group_access'] = array(
 +      'active' => '1',
@@ -61,7 +60,7 @@ index cd8b2c0..d3b99f5 100644
 +      'translatable' => '0',
 +      'type' => 'list_integer',
 +    );
-+  }
++
 +
 +  // Exported field_base: 'field_og_access_default_value'
 +  $field_bases['field_og_access_default_value'] = array(
@@ -124,7 +123,7 @@ index cd8b2c0..d3b99f5 100644
    // Exported field_base: 'group_group'
    $field_bases['group_group'] = array(
      'active' => '1',
-@@ -60,7 +175,7 @@ function commons_groups_field_default_field_bases() {
+@@ -60,7 +174,7 @@ function commons_groups_field_default_field_bases() {
      'locked' => '0',
      'module' => 'entityreference',
      'settings' => array(
@@ -133,7 +132,7 @@ index cd8b2c0..d3b99f5 100644
        'handler_settings' => array(
          'behaviors' => array(
            'og_behavior' => array(
-@@ -137,7 +252,7 @@ function commons_groups_field_default_field_bases() {
+@@ -137,7 +251,7 @@ function commons_groups_field_default_field_bases() {
      'locked' => '0',
      'module' => 'entityreference',
      'settings' => array(
@@ -142,7 +141,7 @@ index cd8b2c0..d3b99f5 100644
        'handler_settings' => array(
          'behaviors' => array(
            'og_behavior' => array(
-@@ -186,5 +301,31 @@ function commons_groups_field_default_field_bases() {
+@@ -186,5 +300,31 @@ function commons_groups_field_default_field_bases() {
      'type' => 'image',
    );
  
@@ -175,76 +174,118 @@ index cd8b2c0..d3b99f5 100644
    return $field_bases;
  }
 diff --git a/commons_groups.features.field_instance.inc b/commons_groups.features.field_instance.inc
-index 653dfdf..36dda8c 100644
+index 653dfdf..77a4b65 100644
 --- a/commons_groups.features.field_instance.inc
 +++ b/commons_groups.features.field_instance.inc
-@@ -61,6 +61,59 @@ function commons_groups_field_default_field_instances() {
-     ),
-   );
+@@ -18,10 +18,243 @@ function commons_groups_field_default_field_instances() {
+       }
+     }
+   }
++  $group_bundles = og_get_all_group_bundle();
++  if (!empty($group_bundles['node'])) {
++    foreach($group_bundles['node'] as $bundle => $name) {
++      commons_groups_field_definition_group($field_instances, 'node', $bundle);
++    }
++  }
  
-+  if (module_exists('og_access')) {
-+    // Exported field_instance: 'node-group-group_access'
-+    $field_instances['node-group-group_access'] = array(
-+      'bundle' => 'group',
-+      'default_value' => array(
-+        0 => array(
-+          'value' => 0,
-+        ),
-+      ),
-+      'deleted' => '0',
-+      'description' => '',
-+      'display' => array(
-+        'default' => array(
-+          'label' => 'above',
-+          'module' => 'list',
-+          'settings' => array(),
-+          'type' => 'list_default',
-+          'weight' => 4,
-+        ),
-+        'teaser' => array(
-+          'label' => 'above',
-+          'settings' => array(),
-+          'type' => 'hidden',
-+          'weight' => 0,
-+        ),
+-  // Exported field_instance: 'node-group-body'
+-  $field_instances['node-group-body'] = array(
+-    'bundle' => 'group',
++
++
++  // Exported field_instance: 'og_membership-og_membership_type_default-og_membership_request'
++  $field_instances['og_membership-og_membership_type_default-og_membership_request'] = array(
++    'bundle' => 'og_membership_type_default',
++    'default_value' => NULL,
++    'deleted' => '0',
++    'description' => 'This is the text a user may send to the group administrators.',
++    'display' => array(
++      'default' => array(
++        'label' => 'above',
++        'module' => 'text',
++        'settings' => array(),
++        'type' => 'text_default',
++        'weight' => 0,
 +      ),
-+      'entity_type' => 'node',
-+      'field_name' => 'group_access',
-+      'label' => 'Group visibility',
-+      'required' => TRUE,
++    ),
++    'entity_type' => 'og_membership',
++    'field_name' => 'og_membership_request',
++    'label' => 'Request message',
++    'required' => FALSE,
++    'settings' => array(
++      'text_processing' => 0,
++      'user_register_form' => FALSE,
++    ),
++    'widget' => array(
++      'module' => 'text',
 +      'settings' => array(
-+        'user_register_form' => FALSE,
++        'rows' => 5,
 +      ),
-+      'view modes' => array(
-+        'full' => array(
-+          'label' => 'above',
-+          'type' => 'options_onoff',
-+        ),
-+        'teaser' => array(
-+          'label' => 'above',
-+          'type' => 'options_onoff',
-+        ),
++      'type' => 'text_textarea',
++      'weight' => 0,
++    ),
++  );
++
++  // Translatables
++  // Included for use with string extractors like potx.
++  t('Determine if this is an OG group.');
++  t('Group');
++  t('Group membership');
++  t('Group visibility');
++  t('Group content visibility');
++  t('Group roles and permissions');
++  t('Request message');
++  t('This is the text a user may send to the group administrators.');
++  t('Group Logo');
++  t('Hide contributed content from non-members');
++  t('Privacy settings');
++  return $field_instances;
++}
++
++function commons_groups_field_definition_group(&$field_instances, $entity_type, $bundle) {
++   // Exported field_instance: 'node-group-field_topics'
++  $field_instances["$entity_type-$bundle-field_topics"] = array(
++    'bundle' => $bundle,
++    'default_value' => NULL,
++    'deleted' => '0',
++    'description' => '',
++    'display' => array(
++      'default' => array(
++        'label' => 'above',
++        'module' => 'taxonomy',
++        'settings' => array(),
++        'type' => 'taxonomy_term_reference_link',
++        'weight' => '2',
 +      ),
-+      'widget' => array(
-+        'module' => 'options',
++      'teaser' => array(
++        'label' => 'above',
 +        'settings' => array(),
-+        'type' => 'options_buttons',
-+        'weight' => 41,
++        'type' => 'hidden',
++        'weight' => 0,
 +      ),
-+      'widget_type' => 'options_select',
-+    );
-+  }
++    ),
++    'entity_type' => 'node',
++    'field_name' => 'field_topics',
++    'label' => 'Topics',
++    'required' => 0,
++    'settings' => array(
++      'user_register_form' => FALSE,
++    ),
++    'widget' => array(
++      'active' => 0,
++      'module' => 'taxonomy',
++      'settings' => array(
++        'autocomplete_path' => 'taxonomy/autocomplete',
++        'size' => 60,
++      ),
++      'type' => 'taxonomy_autocomplete',
++      'weight' => '6',
++    ),
++  );
 +
-    // Exported field_instance: 'node-group-group_group'
-   $field_instances['node-group-group_group'] = array(
-     'bundle' => 'group',
-@@ -190,14 +243,155 @@ function commons_groups_field_default_field_instances() {
-     ),
-   );
- 
 +  // Exported field_instance: 'node-group-field_og_subscribe_settings'
-+  $field_instances['node-group-field_og_subscribe_settings'] = array(
-+    'bundle' => 'group',
++  $field_instances["$entity_type-$bundle-field_og_subscribe_settings"] = array(
++    'bundle' => $bundle,
 +    'default_value' => array(
 +      0 => array(
 +        'value' => 'anyone',
@@ -284,8 +325,8 @@ index 653dfdf..36dda8c 100644
 +  );
 +
 +  // Exported field_instance: 'node-group-field_og_access_default_value'
-+  $field_instances['node-group-field_og_access_default_value'] = array(
-+    'bundle' => 'group',
++  $field_instances["$entity_type-$bundle-field_og_access_default_value"] = array(
++    'bundle' => $bundle,
 +    'default_value' => array(
 +      0 => array(
 +        'value' => 0,
@@ -327,8 +368,8 @@ index 653dfdf..36dda8c 100644
 +  );
 +
 +  // Exported field_instance: 'node-group-og_roles_permissions'
-+  $field_instances['node-group-og_roles_permissions'] = array(
-+    'bundle' => 'group',
++  $field_instances["$entity_type-$bundle-og_roles_permissions"] = array(
++    'bundle' => $bundle,
 +    'default_value' => array(
 +      0 => array(
 +        'value' => 1,
@@ -377,28 +418,104 @@ index 653dfdf..36dda8c 100644
 +      'weight' => 1,
 +    ),
 +  );
-+
-   // Translatables
-   // Included for use with string extractors like potx.
-   t('Determine if this is an OG group.');
-   t('Group');
-   t('Group membership');
-+  t('Group visibility');
-+  t('Group content visibility');
-+  t('Group roles and permissions');
-   t('Request message');
-   t('This is the text a user may send to the group administrators.');
-   t('Group Logo');
-+  t('Hide contributed content from non-members');
-+  t('Privacy settings');
-   return $field_instances;
- }
++   // Exported field_instance: 'node-group-body'
++  $field_instances["$entity_type-$bundle-body"] = array(
++    'bundle' => $bundle,
+     'default_value' => NULL,
+     'deleted' => '0',
+     'description' => '',
+@@ -61,9 +294,10 @@ function commons_groups_field_default_field_instances() {
+     ),
+   );
  
-@@ -271,6 +465,59 @@ function commons_groups_field_definition(&$field_instances, $entity_type, $bundl
++
+    // Exported field_instance: 'node-group-group_group'
+-  $field_instances['node-group-group_group'] = array(
+-    'bundle' => 'group',
++  $field_instances["$entity_type-$bundle-group_group"] = array(
++    'bundle' => $bundle,
+     'default_value' => array(
+       0 => array(
+         'value' => 1,
+@@ -116,53 +350,124 @@ function commons_groups_field_default_field_instances() {
      ),
    );
  
+-
+-  // Exported field_instance: 'og_membership-og_membership_type_default-og_membership_request'
+-  $field_instances['og_membership-og_membership_type_default-og_membership_request'] = array(
+-    'bundle' => 'og_membership_type_default',
+-    'default_value' => NULL,
+-    'deleted' => '0',
+-    'description' => 'This is the text a user may send to the group administrators.',
+-    'display' => array(
+-      'default' => array(
+-        'label' => 'above',
+-        'module' => 'text',
 +  if (module_exists('og_access')) {
++    // Exported field_instance: 'node-group-group_access'
++    $field_instances["$entity_type-$bundle-group_access"] = array(
++      'bundle' => $bundle,
++      'default_value' => array(
++        0 => array(
++          'value' => 0,
++        ),
++      ),
++      'deleted' => '0',
++      'description' => '',
++      'display' => array(
++        'default' => array(
++          'label' => 'above',
++          'module' => 'list',
++          'settings' => array(),
++          'type' => 'list_default',
++          'weight' => 4,
++        ),
++        'teaser' => array(
++          'label' => 'above',
++          'settings' => array(),
++          'type' => 'hidden',
++          'weight' => 0,
++        ),
++      ),
++      'entity_type' => 'node',
++      'field_name' => 'group_access',
++      'label' => 'Group visibility',
++      'required' => TRUE,
++      'settings' => array(
++        'user_register_form' => FALSE,
++      ),
++      'view modes' => array(
++        'full' => array(
++          'label' => 'above',
++          'type' => 'options_onoff',
++        ),
++        'teaser' => array(
++          'label' => 'above',
++          'type' => 'options_onoff',
++        ),
++      ),
++      'widget' => array(
++        'module' => 'options',
+         'settings' => array(),
+-        'type' => 'text_default',
+-        'weight' => 0,
++        'type' => 'options_buttons',
++        'weight' => 41,
+       ),
+-    ),
+-    'entity_type' => 'og_membership',
+-    'field_name' => 'og_membership_request',
+-    'label' => 'Request message',
+-    'required' => FALSE,
+-    'settings' => array(
+-      'text_processing' => 0,
+-      'user_register_form' => FALSE,
+-    ),
+-    'widget' => array(
+-      'module' => 'text',
++      'widget_type' => 'options_select',
++    );
 +    // Exported field_instance: '[entity]-[bundle]-group_content_access'
 +    $field_instances["$entity_type-$bundle-group_content_access"] = array(
 +      'bundle' => $bundle,
@@ -428,9 +545,14 @@ index 653dfdf..36dda8c 100644
 +      'field_name' => 'group_content_access',
 +      'label' => 'Group content visibility',
 +      'required' => TRUE,
-+      'settings' => array(
+       'settings' => array(
+-        'rows' => 5,
 +        'user_register_form' => FALSE,
-+      ),
+       ),
+-      'type' => 'text_textarea',
+-      'weight' => 0,
+-    ),
+-  );
 +      'view modes' => array(
 +        'full' => array(
 +          'label' => 'above',
@@ -450,15 +572,146 @@ index 653dfdf..36dda8c 100644
 +      'widget_type' => 'options_select',
 +    );
 +  }
-+
-   // Exported field_instance: 'node-group-field_group_logo'
-   $field_instances['node-group-field_group_logo'] = array(
+ 
+- // Exported field_instance: 'node-group-field_topics'
+-  $field_instances['node-group-field_topics'] = array(
++  // Exported field_instance: 'node-group-field_group_logo'
++  $field_instances["$entity_type-$bundle-field_group_logo"] = array(
      'bundle' => 'group',
+-    'default_value' => NULL,
+     'deleted' => '0',
+     'description' => '',
+     'display' => array(
+       'default' => array(
+-        'label' => 'above',
+-        'module' => 'taxonomy',
+-        'settings' => array(),
+-        'type' => 'taxonomy_term_reference_link',
+-        'weight' => '2',
++        'label' => 'hidden',
++        'module' => 'image',
++        'settings' => array(
++          'image_link' => '',
++          'image_style' => '50x50',
++        ),
++        'type' => 'image',
++        'weight' => '0',
+       ),
+       'teaser' => array(
+         'label' => 'above',
+@@ -172,36 +477,34 @@ function commons_groups_field_default_field_instances() {
+       ),
+     ),
+     'entity_type' => 'node',
+-    'field_name' => 'field_topics',
+-    'label' => 'Topics',
++    'field_name' => 'field_group_logo',
++    'label' => 'Group Logo',
+     'required' => 0,
+     'settings' => array(
++      'alt_field' => 0,
++      'default_image' => 0,
++      'file_directory' => '',
++      'file_extensions' => 'png gif jpg jpeg',
++      'max_filesize' => '20mb',
++      'max_resolution' => '',
++      'min_resolution' => '30x30',
++      'title_field' => 0,
+       'user_register_form' => FALSE,
+     ),
+     'widget' => array(
+-      'active' => 0,
+-      'module' => 'taxonomy',
++      'active' => 1,
++      'module' => 'image',
+       'settings' => array(
+-        'autocomplete_path' => 'taxonomy/autocomplete',
+-        'size' => 60,
++        'preview_image_style' => 'thumbnail',
++        'progress_indicator' => 'throbber',
+       ),
+-      'type' => 'taxonomy_autocomplete',
+-      'weight' => '6',
++      'type' => 'image_image',
++      'weight' => '5',
+     ),
+   );
+ 
+-  // Translatables
+-  // Included for use with string extractors like potx.
+-  t('Determine if this is an OG group.');
+-  t('Group');
+-  t('Group membership');
+-  t('Request message');
+-  t('This is the text a user may send to the group administrators.');
+-  t('Group Logo');
+-  return $field_instances;
+ }
+ 
+-
+ function commons_groups_field_definition(&$field_instances, $entity_type, $bundle) {
+   // Exported field_instance: 'node-post-og_group_ref'
+    $field_instances["$entity_type-$bundle-og_group_ref"] = array(
+@@ -270,54 +573,4 @@ function commons_groups_field_definition(&$field_instances, $entity_type, $bundl
+       'weight' => 5,
+     ),
+   );
+-
+-  // Exported field_instance: 'node-group-field_group_logo'
+-  $field_instances['node-group-field_group_logo'] = array(
+-    'bundle' => 'group',
+-    'deleted' => '0',
+-    'description' => '',
+-    'display' => array(
+-      'default' => array(
+-        'label' => 'hidden',
+-        'module' => 'image',
+-        'settings' => array(
+-          'image_link' => '',
+-          'image_style' => '50x50',
+-        ),
+-        'type' => 'image',
+-        'weight' => '0',
+-      ),
+-      'teaser' => array(
+-        'label' => 'above',
+-        'settings' => array(),
+-        'type' => 'hidden',
+-        'weight' => 0,
+-      ),
+-    ),
+-    'entity_type' => 'node',
+-    'field_name' => 'field_group_logo',
+-    'label' => 'Group Logo',
+-    'required' => 0,
+-    'settings' => array(
+-      'alt_field' => 0,
+-      'default_image' => 0,
+-      'file_directory' => '',
+-      'file_extensions' => 'png gif jpg jpeg',
+-      'max_filesize' => '20mb',
+-      'max_resolution' => '',
+-      'min_resolution' => '30x30',
+-      'title_field' => 0,
+-      'user_register_form' => FALSE,
+-    ),
+-    'widget' => array(
+-      'active' => 1,
+-      'module' => 'image',
+-      'settings' => array(
+-        'preview_image_style' => 'thumbnail',
+-        'progress_indicator' => 'throbber',
+-      ),
+-      'type' => 'image_image',
+-      'weight' => '5',
+-    ),
+-  );
+ }
 diff --git a/commons_groups.info b/commons_groups.info
-index 9e1ea47..93ed60b 100644
+index 9e1ea47..faeb73f 100644
 --- a/commons_groups.info
 +++ b/commons_groups.info
-@@ -21,7 +21,10 @@ dependencies[] = views_load_more
+@@ -21,8 +21,13 @@ dependencies[] = views_load_more
  features[ctools][] = strongarm:strongarm:1
  features[ctools][] = views:views_default:3.0
  features[features_api][] = api:1
@@ -467,17 +720,11 @@ index 9e1ea47..93ed60b 100644
  features[field_base][] = group_group
 +features[field_base][] = og_roles_permissions
  features[field_base][] = og_group_ref
++features[field_base][] = field_og_subscribe_settings
++features[field_base][] = field_og_access_default_value
  features[field_base][] = og_membership_request
  features[field_base][] = og_user_group_ref
-@@ -58,4 +61,6 @@ features[views_view][] = commons_group_moderation
- features[views_view][] = commons_groups_contributors
- features[views_view][] = commons_groups_directory
- features[views_view][] = commons_groups_recent_content
--features[views_view][] = commons_groups_user_groups
-\ No newline at end of file
-+features[views_view][] = commons_groups_user_groups
-+features_exclude[field][node-group-group_group] = node-group-group_group
-+features_exclude[field][node-group-group_access] = node-group-group_access
+ features[field_base][] = field_group_logo
 diff --git a/commons_groups.install b/commons_groups.install
 index 23b8375..1f74383 100644
 --- a/commons_groups.install
@@ -510,7 +757,7 @@ index 23b8375..1f74383 100644
  }
 \ No newline at end of file
 diff --git a/commons_groups.module b/commons_groups.module
-index 0802a8e..b594250 100644
+index 0802a8e..474d833 100644
 --- a/commons_groups.module
 +++ b/commons_groups.module
 @@ -6,6 +6,25 @@
@@ -659,19 +906,30 @@ index 0802a8e..b594250 100644
   */
  function commons_groups_features_pipe_alter(&$pipe, $data, $export) {
    // Prevent Commons Groups related fields from being piped in features
-@@ -217,6 +340,11 @@ function commons_groups_system_info_alter(&$info, $file, $type) {
+@@ -212,6 +335,22 @@ function commons_groups_system_info_alter(&$info, $file, $type) {
+   // and can sucessfully revert the field_instance component back
+   // to its default state.
+   if ($file->name == 'commons_groups') {
++    $group_bundles = og_get_all_group_bundle();
++    if (!empty($group_bundles['node'])) {
++      foreach($group_bundles['node'] as $bundle => $name) {
++        // These field instances should be added to groups regardless of
++        // whether og_access.module is enabled.
++        $info['features']['field_instance'][] = "node-$bundle-field_og_access_default_value";
++        $info['features']['field_instance'][] = "node-$bundle-field_og_subscribe_settings";
++        $info['features']['field_instance'][] = "node-$bundle-og_roles_permissions";
++        // These fields are only necessary when og_access.module is enabled.
++        if (module_exists('og_access')) {
++          $info['features']['field_instance'][] = "node-$bundle-field_og_access_default_value";
++          $info['features']['field_instance'][] = "node-$bundle-group_access";
++          $info['features']['field_instance'][] = "node-$bundle-group_content_access";
++        }
++      }
++    }
+     $group_content_entity_types = commons_groups_get_group_content_entity_types();
+     if (!empty($group_content_entity_types)) {
        foreach ($group_content_entity_types as $entity_type => $bundles) {
-         foreach(array_keys($bundles) as $bundle) {
-           $info['features']['field_instance'][] = "$entity_type-$bundle-og_group_ref";
-+          $info['features']['field_instance'][] = "$entity_type-$bundle-field_og_subscribe_settings";
-+          if (module_exists('og_access')) {
-+            $info['features']['field_instance'][] = "$entity_type-$bundle-field_og_access_default_value";
-+            $info['features']['field_instance'][] = "$entity_type-$bundle-group-group_access";
-+          }
-         }
-       }
-     }
-@@ -236,34 +364,39 @@ function commons_groups_default_message_type_alter(&$defaults) {
+@@ -236,34 +375,39 @@ function commons_groups_default_message_type_alter(&$defaults) {
  
  
  /**
@@ -738,7 +996,7 @@ index 0802a8e..b594250 100644
    }
  }
  
-@@ -429,7 +562,7 @@ function commons_groups_entityreference_default_value($entity_type, $entity, $fi
+@@ -429,7 +573,7 @@ function commons_groups_entityreference_default_value($entity_type, $entity, $fi
      $target = entity_load_single($target_type, $target_id);
      if (entity_access('view', $target_type, $target)
        && og_is_group_type($target_type, $target->type)
@@ -747,7 +1005,7 @@ index 0802a8e..b594250 100644
          $items[] = array('target_id' => $target_id);
      }
    }
-@@ -456,19 +589,120 @@ function commons_groups_default_rules_configuration_alter(&$configs) {
+@@ -456,19 +600,120 @@ function commons_groups_default_rules_configuration_alter(&$configs) {
  }
  
  /**
@@ -872,7 +1130,7 @@ index 0802a8e..b594250 100644
  }
  
  /**
-@@ -550,4 +784,25 @@ function commons_groups_preprocess_views_view_grid(&$variables, $hook) {
+@@ -550,4 +795,25 @@ function commons_groups_preprocess_views_view_grid(&$variables, $hook) {
    if ($variables['view']->name == 'commons_contributors_group' && !empty($variables['title']) && $variables['title'] == 'administrator member') {
      $variables['title'] = t('Organizers');
    }
