You are here

domain_strict.module in Domain Access 7.3

Forces users to be assigned to a domain in order to view content on that domain.

File

domain_strict/domain_strict.module
View source
<?php

/**
 * @defgroup domain_strict Domain Strict: strict access control
 * Forces users to be assigned to a domain in order to view content on that domain.
 */

/**
 * @file
 * Forces users to be assigned to a domain in order to view content on that domain.
 *
 * @ingroup domain_strict
 */

/**
 * Implements hook_node_access_grants_alter().
 *
 * In Domain Strict, we only let users see content on domains that
 * they are registered with.  So we check the $user object in order
 * to set our grants rather than using the default module grants.
 *
 * @ingroup strict
 */
function domain_strict_node_grants_alter(&$grants, $account, $op) {
  $_domain = domain_get_domain();

  // We only act on the 'view' operation.
  if ($op != 'view') {
    return;
  }

  // Erase the default domain_id grants.
  $grants['domain_id'] = array();

  // Get the user-assigned domains.
  $domains = domain_get_user_domains($account);
  if (!empty($domains)) {
    foreach ($domains as $key => $value) {

      // If the user has access to the current domain, set that grant.
      if ($value == $_domain['domain_id']) {
        $grants['domain_id'][] = $value;
      }
    }
  }
}

Related topics

Functions

Namesort descending Description
domain_strict_node_grants_alter Implements hook_node_access_grants_alter().