You are here

function webform_demo_group_block_access in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_demo/webform_demo_group/webform_demo_group.module \webform_demo_group_block_access()

Implements hook_block_access().

File

modules/webform_demo/webform_demo_group/webform_demo_group.module, line 16
Demonstrate how to use integrate the Webform module with the Group module.

Code

function webform_demo_group_block_access(Block $block, $operation, AccountInterface $account) {

  // Block access to group operation block when there is no group context in
  // the Bartik theme.
  // @see \Drupal\group\Plugin\Block\GroupOperationsBlock
  if ($operation === 'view' && $block
    ->getPluginId() === 'group_operations' && $block
    ->id() === 'group_operations' && $block
    ->getTheme() === 'bartik') {

    // Get the current route group context.
    // @see \Drupal\group\Context\GroupRouteContext;
    // @see \Drupal\group\Plugin\views\access\GroupPermission

    /** @var \Drupal\Core\Plugin\Context\ContextProviderInterface $context_provider */
    $context_provider = \Drupal::service('group.group_route_context');
    $contexts = $context_provider
      ->getRuntimeContexts([
      'group',
    ]);
    $group = $contexts['group']
      ->getContextValue();
    if (!$group || !$group instanceof GroupInterface) {
      return AccessResult::forbidden();
    }
  }

  // No opinion.
  return AccessResult::neutral();
}