function _social_group_get_current_group in Open Social 8.7
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8.2 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8.3 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8.4 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8.5 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8.6 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 8.8 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 10.3.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 10.0.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 10.1.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
- 10.2.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
Get current Group entity from the route.
Return value
\Drupal\group\Entity\GroupInterface Returns the group object.
40 calls to _social_group_get_current_group()
- FlexibleGroupJoinPermissionAccessCheck::access in modules/
social_features/ social_group/ modules/ social_group_flexible_group/ src/ Access/ FlexibleGroupJoinPermissionAccessCheck.php - Checks access.
- GroupAddBookBlock::blockAccess in modules/
social_features/ social_book/ src/ Plugin/ Block/ GroupAddBookBlock.php - Custom access logic to display the block.
- GroupAddBookBlock::build in modules/
social_features/ social_book/ src/ Plugin/ Block/ GroupAddBookBlock.php - Builds and returns the renderable array for this block plugin.
- GroupAddEventBlock::blockAccess in modules/
social_features/ social_group/ src/ Plugin/ Block/ GroupAddEventBlock.php - Custom access logic to display the block.
- GroupAddEventBlock::build in modules/
social_features/ social_group/ src/ Plugin/ Block/ GroupAddEventBlock.php - Builds and returns the renderable array for this block plugin.
File
- modules/
social_features/ social_group/ social_group.module, line 1155 - The Social group module.
Code
function _social_group_get_current_group($node = NULL) {
$cache =& drupal_static(__FUNCTION__, []);
// For the same $node input, within the same request the return is always
// the same.
$nid = NULL;
if (is_null($node)) {
$nid = -1;
}
elseif ($node instanceof NodeInterface) {
$nid = $node
->id();
}
// If we have a cache key and it has a value, we're done early.
if (!is_null($nid) && isset($cache[$nid])) {
// Translate FALSE (so isset works) back to NULL.
return $cache[$nid] ?: NULL;
}
$group = \Drupal::routeMatch()
->getParameter('group');
if (!is_object($group) && !is_null($group)) {
$group = \Drupal::entityTypeManager()
->getStorage('group')
->load($group);
}
else {
$node = is_object($node) ? $node : \Drupal::routeMatch()
->getParameter('node');
if (is_object($node) && !is_null($node)) {
$node_entity = [
'target_type' => 'node',
'target_id' => $node
->id(),
];
$gid_from_entity = \Drupal::service('social_group.helper_service')
->getGroupFromEntity($node_entity);
if ($gid_from_entity !== NULL) {
$group = \Drupal::entityTypeManager()
->getStorage('group')
->load($gid_from_entity);
}
}
}
// If we have a cache key we store the value.
if (!is_null($nid)) {
// Translate NULL to FALSE so that isset works.
$cache[$nid] = isset($group) ? $group : FALSE;
}
return $group;
}