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

Commit

Permalink
No need to inject the GroupAudienceHelper service, the GroupTypeManag…
Browse files Browse the repository at this point in the history
…er also provides this information.
  • Loading branch information
pfrenssen committed Jul 29, 2020
1 parent 86a4484 commit ce84867
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
2 changes: 1 addition & 1 deletion og.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- { name: 'cache.context'}
og.access:
class: Drupal\og\OgAccess
arguments: ['@config.factory', '@current_user', '@module_handler', '@og.group_type_manager', '@og.permission_manager', '@og.membership_manager', '@og.group_audience_helper']
arguments: ['@config.factory', '@current_user', '@module_handler', '@og.group_type_manager', '@og.permission_manager', '@og.membership_manager']
og.context:
class: Drupal\og\ContextProvider\OgContext
arguments: ['@plugin.manager.og.group_resolver', '@config.factory']
Expand Down
15 changes: 2 additions & 13 deletions src/OgAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ class OgAccess implements OgAccessInterface {
*/
protected $membershipManager;

/**
* The OG group audience helper.
*
* @var \Drupal\og\OgGroupAudienceHelperInterface
*/
protected $groupAudienceHelper;

/**
* Constructs the OgAccess service.
*
Expand All @@ -98,17 +91,14 @@ class OgAccess implements OgAccessInterface {
* The permission manager.
* @param \Drupal\og\MembershipManagerInterface $membership_manager
* The group membership manager.
* @param \Drupal\og\OgGroupAudienceHelperInterface $group_audience_helper
* The OG group audience helper.
*/
public function __construct(ConfigFactoryInterface $config_factory, AccountProxyInterface $account_proxy, ModuleHandlerInterface $module_handler, GroupTypeManagerInterface $group_manager, PermissionManagerInterface $permission_manager, MembershipManagerInterface $membership_manager, OgGroupAudienceHelperInterface $group_audience_helper) {
public function __construct(ConfigFactoryInterface $config_factory, AccountProxyInterface $account_proxy, ModuleHandlerInterface $module_handler, GroupTypeManagerInterface $group_manager, PermissionManagerInterface $permission_manager, MembershipManagerInterface $membership_manager) {
$this->configFactory = $config_factory;
$this->accountProxy = $account_proxy;
$this->moduleHandler = $module_handler;
$this->groupTypeManager = $group_manager;
$this->permissionManager = $permission_manager;
$this->membershipManager = $membership_manager;
$this->groupAudienceHelper = $group_audience_helper;
}

/**
Expand Down Expand Up @@ -230,8 +220,7 @@ public function userAccessEntity($operation, EntityInterface $entity, AccountInt
}
}

$is_group_content = $this->groupAudienceHelper->hasGroupAudienceField($entity_type_id, $bundle);
if ($is_group_content) {
if ($this->groupTypeManager->isGroupContent($entity_type_id, $bundle)) {
$cache_tags = $entity_type->getListCacheTags();

// The entity might be a user or a non-user entity.
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Unit/OgAccessEntityTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ protected function setUp(): void {
$this->groupContentEntity->getEntityTypeId()->willReturn($entity_type_id);
$this->addCache($this->groupContentEntity);

// If the group audience helper is asked if the group content entity has any
// group audience fields, it is expected that this will return TRUE.
$this->groupAudienceHelper->hasGroupAudienceField($entity_type_id, $bundle)
// If the group type manager is asked if the group content entity is group
// content, it is expected that this will return TRUE.
$this->groupTypeManager->isGroupContent($entity_type_id, $bundle)
->willReturn(TRUE);

// It is expected that a list of entity operation permissions is retrieved
Expand Down
13 changes: 1 addition & 12 deletions tests/src/Unit/OgAccessTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ class OgAccessTestBase extends UnitTestCase {
*/
protected $membershipManager;

/**
* The OG group audience helper.
*
* @var \Drupal\og\OgGroupAudienceHelperInterface
*/
protected $groupAudienceHelper;

/**
* The entity type manager service.
*
Expand Down Expand Up @@ -178,8 +171,6 @@ protected function setUp(): void {
$this->membershipManager->getGroupCount(Argument::any())->willReturn(1);
$this->membership->getRoles()->willReturn([$this->ogRole->reveal()]);

$this->groupAudienceHelper = $this->prophesize(OgGroupAudienceHelperInterface::class);

// @todo: Move to test.
$this->ogRole->isAdmin()->willReturn(FALSE);
$this->ogRole->getPermissions()->willReturn(['update group']);
Expand All @@ -196,8 +187,7 @@ protected function setUp(): void {
$module_handler->reveal(),
$this->groupTypeManager->reveal(),
$this->permissionManager->reveal(),
$this->membershipManager->reveal(),
$this->groupAudienceHelper->reveal()
$this->membershipManager->reveal()
);

$container = new ContainerBuilder();
Expand All @@ -207,7 +197,6 @@ protected function setUp(): void {
$container->set('module_handler', $this->prophesize(ModuleHandlerInterface::class)->reveal());
$container->set('og.group_type_manager', $this->groupTypeManager->reveal());
$container->set('og.membership_manager', $this->membershipManager->reveal());
$container->set('og.group_audience_helper', $this->groupAudienceHelper->reveal());

// This is for caching purposes only.
$container->set('current_user', $this->user->reveal());
Expand Down

0 comments on commit ce84867

Please sign in to comment.