<?php
/**
 * @file
 * Code for the Commons Group Homepages feature.
 */

include_once 'commons_groups_pages.features.inc';

/**
 * Implements hook_system_info_alter().
 */
function commons_groups_pages_system_info_alter(&$info, $file, $type) {
  // Commons Groups dynamically adds the og_group_ref field to
  // content types that request it by altering the
  // commons_groups_entity_types variable.
  // We must add a corresponding line for each field instance
  // to commons_groups.info so that Features is aware of the instance
  // and can successfully revert the field_instance component back
  // to its default state.
  if ($file->name == 'commons_groups_pages') {
    $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']['panelizer_defaults'][] = "node:$bundle:default";
        $info['features']['panelizer_defaults'][] = "node:$bundle:default:teaser";
        $info['features']['variable'][] = "panelizer_defaults_node_$bundle";
      }
    }
  }
}
