Skip to content

Commit

Permalink
Replace domain group resolver with localgov_microsites_group_get_by_c… (
Browse files Browse the repository at this point in the history
#425)

* Replace domain group resolver with localgov_microsites_group_get_by_context() function.

* Remove unused use statement.

* Previous code allowed for the possibility that there was not a group context.

---------

Co-authored-by: ekes <ekes@iskra.net>
  • Loading branch information
finnlewis and ekes committed Apr 23, 2024
1 parent 8801077 commit b8b3a0e
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions modules/localgov_microsites_media/localgov_microsites_media.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@

use Drupal\Core\Session\AccountInterface;
use Drupal\group\Access\GroupAccessResult;
use Drupal\group\Entity\GroupInterface;

/**
* Implements hook_ENTITY_TYPE_create_access() for node entities.
*/
function localgov_microsites_media_node_create_access(AccountInterface $account, array $context, $entity_bundle) {

// Allow group users to add media items to new nodes.
$group_id = \Drupal::service('domain_group_resolver')->getActiveDomainGroupId();
if (empty($group_id) &&
($group = \Drupal::service('current_route_match')->getParameter('group')) &&
($group instanceof GroupInterface)
) {
$group_id = $group->id();
}
if ($group_id) {
$group = \Drupal::entityTypeManager()->getStorage('group')->load($group_id);
$group = localgov_microsites_group_get_by_context();
if ($group) {
$permission = 'create group_node:' . $entity_bundle . ' entity';
return GroupAccessResult::allowedIfHasGroupPermissions($group, $account, [$permission], 'AND');
}

}

0 comments on commit b8b3a0e

Please sign in to comment.