Skip to content
This repository was archived by the owner on Aug 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e4a3d2a
Add group field type, add subscribe formatter
damiankloip Nov 24, 2015
fd8ad87
Add default display to og_ui entity_bundle_info_alter instead, add se…
damiankloip Nov 24, 2015
6dcdbea
Convert _og_get_group_audience_fields to Og:: method
damiankloip Nov 24, 2015
480a9b2
Add computed boolean value for group field value
damiankloip Nov 30, 2015
1e3f65b
Add helper to get option labels from Og::getAllGroupAudienceFields
damiankloip Nov 30, 2015
ddd6cc4
Add default setting value for field_name, always use audience field o…
damiankloip Nov 30, 2015
0d680c3
Feedback form Amitai and code tidy of GroupSubscriberFormatter::viewE…
damiankloip Nov 30, 2015
c880869
Simplify settingsSummary method
damiankloip Nov 30, 2015
2c03acd
Remove usage of group_value setting
damiankloip Nov 30, 2015
9caeb7e
Use Og::isMember
damiankloip Dec 2, 2015
3a0d662
Add usage of OgGroupAudienceHelper::checkFieldCardinality
damiankloip Dec 2, 2015
1ad173e
Use field_name setting
damiankloip Dec 2, 2015
13f5efc
Convert links to use url parameters
damiankloip Dec 2, 2015
b0489c7
Use OgAccess::userAccess in group formatter
damiankloip Dec 7, 2015
69a330f
Rename subscribe/unsubscribe routes
damiankloip Dec 7, 2015
76951bc
Update subscribe formatter to use OgGroupAudienceHelper::getMatchingF…
damiankloip Jan 4, 2016
2aa966e
Merge 8.x-1.x
amitaibu Aug 4, 2016
cc5c147
Merge branch 'og-ui-subscribe-routes' into 40-group-formatter
amitaibu Aug 4, 2016
28e4918
Cleanup old code
amitaibu Aug 4, 2016
6cef122
Prevent caching of links
amitaibu Aug 4, 2016
b566311
Sniffer fixes
amitaibu Aug 4, 2016
6d4a5e3
Move formatter to core
amitaibu Aug 4, 2016
f693e8c
Replace field ID
amitaibu Aug 4, 2016
f399bb0
Improve the field description
amitaibu Aug 4, 2016
f831620
Starting adding unit tests
amitaibu Aug 4, 2016
b7b783f
Fix test
amitaibu Aug 4, 2016
1b25120
extend tests [skip ci]
amitaibu Aug 4, 2016
9a18d8c
Merge branch '8.x-1.x' into 40-group-formatter
amitaibu Aug 5, 2016
8aa5a40
Fix group owner test
amitaibu Aug 5, 2016
ef60105
Sniffer fixes
amitaibu Aug 5, 2016
0848737
Expand tests
amitaibu Aug 5, 2016
0a0e7b9
Merge branch '8.x-1.x' into 40-group-formatter
amitaibu Aug 17, 2016
b44d90d
Add more mocking
amitaibu Aug 17, 2016
e187985
Fix typo
amitaibu Aug 17, 2016
f3a04aa
Fix logic and add tests
amitaibu Aug 17, 2016
f3d1763
Fix pending subscribe
amitaibu Aug 17, 2016
e871312
Tests the formatter for no subscribe permission.
amitaibu Aug 17, 2016
c873f58
Test blocked member
amitaibu Aug 17, 2016
2d0b5b6
Remove unsubscribe permission
amitaibu Aug 17, 2016
f68b8f7
Add GroupSubscribeFormatterTest.php
amitaibu Aug 17, 2016
8030e43
Sniffer fixes
amitaibu Aug 17, 2016
8339ab7
Cleanup test
amitaibu Aug 17, 2016
b73545b
Add manadatory weight property
amitaibu Aug 17, 2016
4437283
Fix tests
amitaibu Aug 17, 2016
5171578
Improve comment location
amitaibu Aug 17, 2016
56c17a0
Remove obsolete permission
amitaibu Aug 17, 2016
e38d3f9
Upcast the entity ID in the unsubscribe route.
sandervd Aug 19, 2016
08c161a
One does not simply hijack @amitaibu's PR without failing the tests.
pfrenssen Aug 19, 2016
4db893a
Rename class to OgGroupAlwaysTrue
amitaibu Aug 20, 2016
7302fd9
Inject services
amitaibu Aug 20, 2016
dd9d9d0
Merge branch '40-group-formatter-unit-tests' of github.com:amitaibu/o…
amitaibu Aug 20, 2016
57e2f8d
Sniffer fixes
amitaibu Aug 20, 2016
48f6e8e
Lock travis version
amitaibu Aug 20, 2016
d5f89b0
Fix constructor
amitaibu Aug 20, 2016
0414f78
Adapt unit tests
amitaibu Aug 20, 2016
17405dc
Merge 8.x-1.x
amitaibu Aug 24, 2016
0bd2a8b
convert GroupManager to GroupTypeManager
amitaibu Aug 24, 2016
19d486f
Comments fixes
amitaibu Aug 24, 2016
9d2eaab
Call correct method
amitaibu Aug 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use Drupal\user\UserInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
Expand Down Expand Up @@ -169,6 +171,47 @@ function og_entity_create_access(AccountInterface $account, array $context, $bun
return $required ? AccessResult::forbiddenIf($node_access_strict) : AccessResult::neutral();
}

/**
*
* Implements hook_entity_bundle_field_info().
*
* Add a read only property to group entities as a group flag.
*/
function og_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
if (!Og::isGroup($entity_type->id(), $bundle)) {
// Not a group type.
return NULL;
}

$fields = [];
$fields['og_group'] = BaseFieldDefinition::create('og_group')
->setLabel(t('OG Group'))
->setComputed(TRUE)
->setTranslatable(FALSE)
->setDefaultValue(TRUE)
->setReadOnly(TRUE);

return $fields;
}

/**
* Implements hook_entity_bundle_field_info_alter().
*
* Set the default field formatter of fields of type OG group.
*/
function og_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
if (!isset($fields['og_group'])) {
// No OG group fields.
return;
}

$fields['og_group']->setDisplayOptions('view', [
'weight' => 0,
'type' => 'og_group_subscribe',
])->setDisplayConfigurable('view', TRUE);
}


/**
* Implements hook_field_formatter_info_alter().
*
Expand Down
13 changes: 8 additions & 5 deletions og.routing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Routes for Organic groups.

og.subscribe:
path: 'group/{entity_type_id}/{entity_id}/subscribe/{membership_type}'
path: 'group/{entity_type_id}/{group}/subscribe/{membership_type}'
defaults:
_controller: '\Drupal\og\Controller\SubscriptionController::subscribe'
_title: 'Join Group'
Expand All @@ -13,16 +13,19 @@ og.subscribe:
_access: 'TRUE'
options:
parameters:
group:
type: entity:{entity_type_id}
membership_type:
type: entity:og_membership_type



og.unsubscribe:
path: 'group/{entity_type_id}/{entity_id}/unsubscribe'
path: 'group/{entity_type_id}/{group}/unsubscribe'
defaults:
_controller: '\Drupal\og\Controller\SubscriptionController::unsubscribe'
_title: 'Leave Group'
requirements:
_user_is_logged_in: 'TRUE'
_og_user_access_group: 'unsubscribe'
options:
parameters:
group:
type: entity:{entity_type_id}
1 change: 1 addition & 0 deletions og_ui/og_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change in this file. It seems to be unused, but it is strange that PHP_CodeSniffer did not pick up on this.

use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
Expand Down
29 changes: 7 additions & 22 deletions src/Controller/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Drupal\og\Controller;

use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\og\OgMembershipTypeInterface;
use Drupal\user\Entity\User;
use Drupal\user\EntityOwnerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\og\Og;
use Drupal\og\OgAccess;
Expand Down Expand Up @@ -47,11 +47,9 @@ public static function create(ContainerInterface $container) {
/**
* Subscribe a user to group.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param string $entity_type_id
* The entity type of the group entity.
* @param string|int $entity_id
* @param \Drupal\Core\Entity\EntityInterface $group
* The entity ID of the group entity.
* @param \Drupal\og\OgMembershipTypeInterface $membership_type
* The membership type to be used for creating the membership.
Expand All @@ -60,16 +58,8 @@ public static function create(ContainerInterface $container) {
* Redirect user or show access denied if they are not allowed to subscribe,
* otherwise provide a subscribe confirmation form.
*/
public function subscribe(Request $request, $entity_type_id, $entity_id, OgMembershipTypeInterface $membership_type) {
try {
$entity_storage = $this->entityTypeManager()->getStorage($entity_type_id);
}
catch (PluginNotFoundException $e) {
// Not a valid entity type.
throw new AccessDeniedHttpException();
}

if (!$group = $entity_storage->load($entity_id)) {
public function subscribe($entity_type_id, EntityInterface $group, OgMembershipTypeInterface $membership_type) {
if (!$group instanceof ContentEntityInterface) {
// Not a valid entity.
throw new AccessDeniedHttpException();
}
Expand Down Expand Up @@ -142,19 +132,14 @@ public function subscribe(Request $request, $entity_type_id, $entity_id, OgMembe
/**
* Unsubscribe a user from group.
*
* @param string $entity_type_id
* The entity type of the group entity.
* @param string|int $entity_id
* @param \Drupal\core\Entity\EntityInterface $group
* The entity ID of the group entity.
*
* @return mixed
* Redirect user or show access denied if they are not allowed to subscribe,
* otherwise provide an un-subscribe confirmation form.
*/
public function unsubscribe($entity_type_id, $entity_id) {
$entity_storage = $this->entityTypeManager()->getStorage($entity_type_id);
$group = $entity_storage->load($entity_id);

public function unsubscribe(EntityInterface $group) {
$user = $this->currentUser();

if (!$membership = Og::getMembership($group, $user)) {
Expand Down
7 changes: 0 additions & 7 deletions src/EventSubscriber/OgEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ public function provideDefaultOgPermissions(PermissionEventInterface $event) {
'roles' => [OgRoleInterface::ANONYMOUS],
'default roles' => [],
]),
new GroupPermission([
'name' => 'unsubscribe',
'title' => t('Unsubscribe from group'),
'description' => t('Allow members to unsubscribe themselves from a group, removing their membership.'),
'roles' => [OgRoleInterface::AUTHENTICATED],
'default roles' => [OgRoleInterface::AUTHENTICATED],
]),
new GroupPermission([
'name' => 'approve and deny subscription',
'title' => t('Approve and deny subscription'),
Expand Down
2 changes: 1 addition & 1 deletion src/GroupTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class GroupTypeManager {
protected $ogRoleManager;

/**
* Constructs an GroupManager object.
* Constructs a GroupTypeManager object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
Expand Down
3 changes: 1 addition & 2 deletions src/Og.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ public static function createMembership(EntityInterface $group, AccountInterface
* Defaults to active memberships.
*
* @return bool
* TRUE if the entity (e.g. the user or node) belongs to a group with
* a certain state.
* TRUE if the user belongs to a group with a certain state.
*/
public static function isMember(EntityInterface $group, AccountInterface $user, $states = [OgMembershipInterface::STATE_ACTIVE]) {
/** @var \Drupal\og\MembershipManagerInterface $membership_manager */
Expand Down
2 changes: 0 additions & 2 deletions src/OgAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class OgAccess implements OgAccessInterface {
* The group manager.
*
* @var \Drupal\og\GroupTypeManager
*
* @todo This should be GroupManagerInterface.
*/
protected $groupTypeManager;

Expand Down
26 changes: 26 additions & 0 deletions src/OgGroupAlwaysTrue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Drupal\og;

use Drupal\Core\TypedData\Plugin\DataType\BooleanData;

/**
* Overridden boolean data type to hardcode TRUE.
*/
class OgGroupAlwaysTrue extends BooleanData {

/**
* {@inheritdoc}
*/
public function getValue() {
return TRUE;
}

/**
* {@inheritdoc}
*/
public function getCastedValue() {
return $this->getValue();
}

}
2 changes: 1 addition & 1 deletion src/OgRoleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OgRoleManager implements OgRoleManagerInterface {
protected $permissionManager;

/**
* Constructs an GroupManager object.
* Constructs an OgRoleManager object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
Expand Down
Loading