You are here

function domain_views_tables in Domain Access 5

@file Provides a Views filter for the Domain Access module.

Original code by mrichar1 see http://drupal.org/node/200714

@in

Implement hook_views_tables(). Provide a filter that restricts a view to only show nodes from a specific domain (by domain_id). Relevant for authenticated users who have superuser permissions and can therefore see all nodes.

File

domain_views/domain_views.module, line 22
Provides a Views filter for the Domain Access module.

Code

function domain_views_tables() {
  $domains = domain_domains();
  $domain_options = array(
    '-1' => t('Any domain -- use with "Is not one of"'),
    '***CURRENT_DOMAIN***' => t('Current Domain'),
  );
  foreach ($domains as $domain) {
    $domain_options[$domain['domain_id']] = $domain['sitename'];
  }
  $domain_form = array(
    '#type' => 'select',
    '#options' => $domain_options,
    '#multiple' => TRUE,
    '#size' => 'size="' . min(8, count($domain_options)) . '"',
  );
  $tables['domain_access'] = array(
    'name' => 'node_access',
    'join' => array(
      'left' => array(
        'table' => 'node',
        'field' => 'nid',
      ),
      'right' => array(
        'field' => 'nid',
      ),
      'extra' => array(
        'realm' => 'domain_id',
      ),
    ),
    'filters' => array(
      'gid' => array(
        'name' => t('Domain Access: Domain'),
        'value' => $domain_form,
        'value-type' => 'array',
        'operator' => 'views_handler_operator_or',
        'help' => t('This will filter a view to only show nodes from the specified domain.'),
      ),
    ),
  );
  $tables['domain'] = array(
    'name' => 'domain',
    'join' => array(
      'left' => array(
        'table' => 'domain_access',
        'field' => 'gid',
      ),
      'right' => array(
        'field' => 'domain_id',
      ),
      'extra' => array(
        'valid' => '1',
      ),
    ),
  );
  return $tables;
}