Example #1
0
 /**
  * Add og_roles_permissions field to the specified entity.
  *
  * @param object $entity
  *    Entity object.
  * @param string $bundle
  *    Entity bundle name.
  */
 public function createOgDefaultContentAccessField($entity = NULL, $bundle = NULL)
 {
     drupal_static_reset('og_fields_info');
     og_create_field(OG_DEFAULT_ACCESS_FIELD, $entity, $bundle);
 }
$_SERVER['HTTP_USER_AGENT'] = 'console';
$modules_to_enable = array('og', 'entity');
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
module_enable(array('og', 'entity'));
// Run cron after installing
drupal_cron_run();
// Create users with ID 2 to 5.
$uids = array();
foreach (range(2, 5) as $i) {
    $values = array('name' => 'og_test_user' . $i, 'mail' => 'og_test_user' . $i . '@example.com', 'pass' => user_password(5), 'status' => 1);
    $account = entity_create('user', $values);
    entity_save('user', $account);
    $uids[] = $account;
}
// Create a group node.
og_create_field(OG_GROUP_FIELD, 'node', 'article');
$values = array('uid' => $uids[0]->uid, 'type' => 'article', 'title' => 'Group node');
$node = entity_create('node', $values);
$node->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
entity_save('node', $node);
// Explicetly set the created timestamp.
$node->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['created'] = 1000000000;
entity_save('node', $node);
// Assign users to group.
$group = og_get_group('node', $node->nid);
$items = array(1 => OG_STATE_ACTIVE, 2 => OG_STATE_PENDING, 3 => OG_STATE_BLOCKED);
foreach ($items as $key => $state) {
    og_group($group->gid, 'user', $uids[$key], $state);
}