You are here

function _social_group_get_current_group in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  2. 8.2 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  3. 8.3 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  4. 8.4 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  5. 8.5 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  6. 8.6 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  7. 8.7 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  8. 8.8 modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  9. 10.3.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  10. 10.0.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  11. 10.1.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()
  12. 10.2.x modules/social_features/social_group/social_group.module \_social_group_get_current_group()

Gets current Group entity from the route.

Parameters

\Drupal\node\NodeInterface|null $node: (optional) The node object or NULL.

Return value

\Drupal\group\Entity\GroupInterface|null Returns the group object.

52 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.

... See full list

File

modules/social_features/social_group/social_group.module, line 1259
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)) {
      $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] = $group ?? FALSE;
  }
  return $group;
}