Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from amitaibu/8.x-1.x
Browse files Browse the repository at this point in the history
Update from original - 201606161837
  • Loading branch information
dakala authored Jun 16, 2016
2 parents a7f1362 + fc03d11 commit 4a21609
Show file tree
Hide file tree
Showing 92 changed files with 8,918 additions and 1,070 deletions.
34 changes: 29 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,54 @@ sudo: false
php:
- 5.5
- 5.6
- 7.0

env:
- DRUPAL_CORE=8.1.x
- DRUPAL_CORE=8.2.x

mysql:
database: og
username: root
encoding: utf8

before_script:
# Remember the current rules test directory for later use in the Drupal
# installation.
# Remove Xdebug as we don't need it and it causes "PHP Fatal error: Maximum
# function nesting level of '256' reached."
# We also don't care if that file exists or not on PHP 7.
- phpenv config-rm xdebug.ini || true

# Remember the current directory for later use in the Drupal installation.
- TESTDIR=$(pwd)

# Navigate out of module directory to prevent blown stack by recursive module
# lookup.
- cd ..

# Create database.
- mysql -e 'create database og'

# Export database variable for kernel tests.
- export SIMPLETEST_DB=mysql://root:@127.0.0.1/og

# Download Drupal 8 core.
- git clone --branch 8.0.x --depth 1 http://git.drupal.org/project/drupal.git
- travis_retry git clone --branch $DRUPAL_CORE --depth 1 https://git.drupal.org/project/drupal.git
- cd drupal

# Install Composer dependencies.
- composer self-update && composer install

# Reference OG in the Drupal site.
- ln -s $TESTDIR modules/og

# Adding DB so PHPUnit could mock the environment.
- export SIMPLETEST_DB=mysql://root:@127.0.0.1/og;
# Start a web server on port 8888 in the background.
- nohup php -S localhost:8888 > /dev/null 2>&1 &

# Wait until the web server is responding.
- until curl -s localhost:8888; do true; done > /dev/null

# Export web server URL for browser tests.
- export SIMPLETEST_BASE_URL=http://localhost:8888

script:
# Run the PHPUnit tests which also include the kernel tests.
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,48 @@ As is the case with Drupal itself, in Organic Groups different permissions can
be assigned to different user roles. This allows group members to perform a
different set of actions, in different group contexts.

### OG Membership Entity

The membership entity that connects a group and a user.

When dealing with non-user entities that are group content, that is content
that is associated with a group, we do it via an entity reference field that
has the default storage. The only information that we hold is that a group
content is referencing a group.

However, when dealing with the user entity we recognize that we need to
special case it. It won't suffice to just hold the reference between the user
and the group content as it will be laking crucial information such as: the
state of the user's membership in the group (active, pending or blocked), the
time the membership was created, the user's OG role in the group, etc.

For this meta data we have the fieldable OgMembership entity, that is always
connecting between a user and a group. There cannot be an OgMembership entity
connecting two non-user entities.

Creating such a relation is done for example in the following way:

```php
$membership = OgMembership::create(['type' => \Drupal\og\OgMembershipInterface::TYPE_DEFAULT]);
$membership
->setUser(2)
->setEntityId(1)
->setGroupEntityType('node')
->setFieldName(OgGroupAudienceHelper::DEFAULT_FIELD)
->save();
```

Notice how the relation of the user to the group also includes the OG
audience field name this association was done by. Like this we are able to
express different membership types such as the default membership that comes
out of the box, or a "premium membership" that can be for example expired
after a certain amount of time (the logic for the expired membership in the
example is out of the scope of OG core).

Having this field separation is what allows having multiple OG audience
fields attached to the user, where each group they are associated with may be
a result of different membership types.

## INSTALLATION DRUPAL 8.x
Note that the following guide is here to get you started. Names for content
types, groups and group content given here are suggestions and are given to
Expand Down
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "drupal/og",
"description": "API to allow associating content with groups.",
"type": "drupal-module",
"license": "GPL-2.0+",
"homepage": "https://drupal.org/project/og",
"support": {
"issues": "https://drupal.org/project/issues/og",
"irc": "irc://irc.freenode.org/drupal-og",
"source": "https://cgit.drupalcode.org/og"
},
"minimum-stability": "dev"
}
4 changes: 2 additions & 2 deletions config/install/og.settings.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group_manager_full_access: true
groups: []
node_access_strict: true
orphans_delete: false
use_queue: false
delete_orphans: false
delete_orphans_plugin_id: simple
54 changes: 48 additions & 6 deletions config/schema/og.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ field.field_settings.og_membership_reference:
type: boolean
label: 'Access Override'

field.storage_settings.og_standard_reference:
type: mapping
label: 'Organic Groups reference field storage settings'
mapping:
target_type:
type: string
label: 'Type of entity to reference'

field.field_settings.og_standard_reference:
type: mapping
label: 'Organic Groups reference field settings'
mapping:
handler:
type: string
label: 'Reference method'
handler_settings:
type: entity_reference_selection.[%parent.handler]
label: 'Organic Groups reference selection plugin settings'
access_override:
type: boolean
label: 'Access Override'

og.settings:
type: config_object
label: 'Organic Groups settings'
Expand All @@ -34,12 +56,12 @@ og.settings:
node_access_strict:
type: boolean
label: 'Strict node access permissions'
orphans_delete:
delete_orphans:
type: boolean
label: 'Delete orphaned group content when a group is deleted'
use_queue:
type: boolean
label: 'Use queue'
delete_orphans_plugin_id:
type: string
label: 'The method to use when deleting orphaned group content'

og.settings.group.*:
type: sequence
Expand Down Expand Up @@ -83,14 +105,34 @@ og.og_role.*:
type: string
label: 'Group ID'
group_type:
type: label
type: string
label: 'Group type'
group_bundle:
type: label
type: string
label: 'Group bundle'
is_admin:
type: boolean
label: 'User is group admin'
permissions:
type: sequence
label: 'Permissions'
sequence:
type: string
label: 'Permission'
role_type:
type: string
label: 'Role type'

field.widget.settings.og_complex:
type: mapping
label: 'OG Group Audience field widget'
mapping:
match_operator:
type: string
label: 'Autocomplete matching'
size:
type: integer
label: 'Size of textfield'
placeholder:
type: label
label: 'Placeholder'
90 changes: 8 additions & 82 deletions og.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,20 @@
* Install, update, and uninstall functions for the Organic groups module.
*/

/**
* Implements hook_uninstall().
*/
function og_uninstall() {
\Drupal::queue('og_orphaned_group_content')->deleteQueue();
\Drupal::queue('og_orphaned_group_content_cron')->deleteQueue();
}

/**
* Implements hook_schema().
*/
function og_schema() {
$schema = array();

$schema['og_role_permission'] = array(
'description' => 'Stores the permissions assigned to user roles per group.',
'fields' => array(
'id' => array(
'type' => 'serial',
'description' => "The role permission unique identifier.",
'unsigned' => TRUE,
'not null' => TRUE,
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: {role}.rid.',
),
'permission' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'A single permission granted to the role identified by rid.',
),
'module' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The module declaring the permission.",
),
),
'primary key' => array('id'),
'indexes' => array(
'permission' => array('permission'),
),
'foreign keys' => array(
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
),
);

$schema['og_role'] = array(
'description' => 'Stores user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique role ID.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's entity type.",
),
'group_bundle' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's bundle name.",
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Unique role name per group.',
),
),
'primary key' => array('rid'),
);

$schema['og_users_roles'] = array(
'description' => 'Maps users to roles.',
'fields' => array(
Expand Down
Loading

0 comments on commit 4a21609

Please sign in to comment.