Group

An Alternative to Organic Groups

Presentation by Kyle Einecker

The bit about me

ctrlADel

@DBridgeChicago

Group

kristiaanvandeneynde

Been around since 2013

~700 installs

My problem with OG

Node
Entity
Entity Reference
Organic Groups
OG Contrib

Based on nodes

UX

DX

Why I went to group

Entity
Group
Group Contrib

Experience

User Experience

Structured like nodes

Top level menu

Define group types

Fieldable

Examples

Developer Experience

Everything is an entity

Groups

Group memberships

Group roles

Everything has it's own class

Groups

Group memberships

Group roles

Built with it's own api

Examples

Add a member to a group

OG


global $user;
$group = node_load($gid);

if (!$group_type) {
  $group_type = 'node';
}

if (!$membership_type) {
  $membership_type = OG_MEMBERSHIP_TYPE_DEFAULT;
}

$is_a_group = $group->group_group[$group->language][0]['value'];

if ($is_a_group && $user) {
  $values = array(
  'entity_type' => 'user',
  'entity' => $user,
  'state' => OG_STATE_ACTIVE,
  'membership_type' => $membership_type
);

og_group($group_type, $gid, $values);
						

Add a member to a group

Group


global $user;
$group = group_load($gid);
$group->addMember($user->uid);
						

Get all group members

OG


$group = node_load($gid);
og_get_group_members_properties($group, array(), 'members', 'node');
						

Get all group members

Group


$group = group_load($gid);
$members = $group->getMembers();
						

Get all group members of all subgroups


$group = group_load($gid);
$members = $group->getMembersRecursive();
						

Group supports subgroups out of the box

Any entity can easily be made a child of a group


/**
 * Implements hook_entity_info_alter().
 */
function gnode_entity_info_alter(&$entity_info) {
  // Nodes can only have one group parent.
  $entity_info['node']['group entity'] = 'single';
}
						

Get all nodes in group

OG


I couldn't find a good answer
						

Get all nodes in group

Group


$group = group_load($gid);
$nodes = $group->getEntitiesOfType('node');
						

Get all entities in group


$group = group_load($gid);
$entities = $group->getEntities();
						

Documentation

addMember


/**
* Add a user to a group.
*
* If the user is anonymous or already a member, nothing changes.
*
* @param int $uid
*   The uid of the member.
* @param array $values
*   (optional) Extra values to add to the GroupMembership entity, like the
*   'roles' property. You cannot overwrite the group id (gid) or user id
*   (uid) with this method. Leave blank to make the user 'just a member'.
*/
public function addMember($uid, array $values = array()) {
						

getMembers


/**
* Get all members of a group.
*
* @return array
*   An array of GroupMembership entities.
*/
public function getMembers() {
						

getMembersRecursive


/**
* Get all members of a group, including subgroup members.
*
* @return array
*   An array of GroupMembership entities.
*/
public function getMembersRecursive() {
						

getEntities


/**
* Get all child entities.
*
* @param bool $flat
*   (optional) Whether or not to flatten the result array.
* @param bool $reset
*   (optional) Whether to reset the internal cache.
*
* @return array
*   An array of child entities, keyed by their type, bundle and entity id.
*   When $flat is set to TRUE, the return value is one big array of
*   entities, which are keyed numerically and not by their entity id!
*/
public function getEntities($flat = FALSE, $reset = FALSE) {
						

getEntitiesOfType


/**
* Get all child entities of a certain type.
*
* @param string $entity_type
*   The type of child entities.
* @param string $bundle
*   (optional) The bundle of the entity type.
*
* @return array
*   An array of child entities of a certain type and optionally bundle,
*   keyed by their entity id.
*/
public function getEntitiesOfType($entity_type, $bundle = NULL) {
						

Integration

Views

Panels

Features

Rules

Anything else an entity integrates with

Contrib Integration

If OG can integrate with it then so can Group

D8 alpha just released

The End

https://www.drupal.org/project/group