You are here

hansel_domain.module in Hansel breadcrumbs 7

Same filename and directory in other branches
  1. 8 domain/hansel_domain.module

Hansel domain integration

This modules provides switches and breadcrumb actions for domains.

File

domain/hansel_domain.module
View source
<?php

/**
 * @file
 * Hansel domain integration
 *
 * This modules provides switches and breadcrumb actions for domains.
 */

/**
 * Implements hook_hansel_action_types().
 */
function hansel_domain_hansel_action_types() {
  return array(
    'add domain' => array(
      'get crumbs' => 'hansel_domain_action_add_domain_get_crumbs',
      'info' => 'hansel_domain_action_add_domain_info',
      'config form' => 'hansel_domain_action_add_domain_config_form',
    ),
  );
}

/**
 * Callback for "add domain" breadcrumb action
 *
 * @param array $arguments Values from the configuration form.
 * @return array
 */
function hansel_domain_action_add_domain_get_crumbs($arguments) {
  global $_domain, $_hansel_flags;
  if (in_array('alias', $_hansel_flags) || in_array('menu', $_hansel_flags)) {

    // Do not add crumbs when generating the alias token or menu path.
    return array();
  }
  if (empty($_domain)) {

    // This happens only if the domain module is not installed correctly
    return array();
  }
  $domain_id = isset($arguments['domain_id']) ? $arguments['domain_id'] : 0;
  if ($domain_id == 0 || $domain_id == $_domain['domain_id']) {
    $domain = $_domain;
  }
  else {
    if (!($domain = domain_load($domain_id))) {
      return array();
    }
  }
  $directory = '';
  if (module_exists('dominion')) {
    if ($subsite = dominion_get_info($domain['domain_id'])) {
      $directory = isset($subsite->directory) ? $subsite->directory : '';
    }
  }
  return array(
    array(
      'title' => $domain['sitename'],
      'href' => $domain['path'] . $directory,
    ),
  );
}

/**
 * Callback for "add domain" action to generate the information line
 *
 * @param array $arguments Values from the configuration form.
 * @return string
 */
function hansel_domain_action_add_domain_info($arguments) {
  if (empty($arguments['domain_id'])) {
    return t('Add current domain');
  }
  elseif ($domain = domain_load($arguments['domain_id'])) {
    return t('Add domain %name', array(
      '%name' => $domain['sitename'],
    ));
  }
  else {
    return t('Add domain (broken)');
  }
}

/**
 * Callback for "add domain" action to generate the config form.
 * 
 * @param array $arguments
 * @return array
 */
function hansel_domain_action_add_domain_config_form($arguments) {
  $form = array();
  $options = array(
    0 => t('Current domain'),
  );
  $domains = db_select('domain', 'd')
    ->fields('d', array(
    'domain_id',
    'sitename',
  ))
    ->orderBy('d.is_default', 'desc')
    ->orderBy('d.sitename', 'asc')
    ->execute()
    ->fetchAllKeyed();
  foreach ($domains as $domain_id => $sitename) {
    $options[$domain_id] = $sitename;
  }
  $form['domain_id'] = array(
    '#type' => 'select',
    '#title' => t('Domain'),
    '#options' => $options,
    '#default_value' => empty($arguments['domain_id']) ? 0 : $arguments['domain_id'],
  );
  return $form;
}

/**
 * Implements hook_hansel_switch_types().
 */
function hansel_domain_hansel_switch_types() {
  return array(
    'subdomain' => array(
      'compare' => 'hansel_domain_switch_subdomain_compare',
    ),
    'domain id' => array(
      'compare' => 'hansel_domain_switch_domain_id_compare',
    ),
  );
}

/**
 * Callback for "subdomain" switch to compare a given value.
 *
 * @param array $arguments
 * @param string $value
 * @return boolean
 */
function hansel_domain_switch_subdomain_compare($arguments, $value) {
  global $_domain;
  return drupal_strtolower($_domain['subdomain']) == drupal_strtolower($value);
}

/**
 * Callback for "domain id" switch to compare a given value.
 *
 * @param array $arguments
 * @param string $value
 * @return boolean
 */
function hansel_domain_switch_domain_id_compare($arguments, $value) {
  global $_domain;
  return $_domain['domain_id'] == $value;
}

/**
 * Implements hook_hansel_cache_parts_alter().
 */
function hansel_domain_hansel_cache_parts_alter(&$parts) {
  global $_domain;
  $parts[] = $_domain['domain_id'];
}

Functions

Namesort descending Description
hansel_domain_action_add_domain_config_form Callback for "add domain" action to generate the config form.
hansel_domain_action_add_domain_get_crumbs Callback for "add domain" breadcrumb action
hansel_domain_action_add_domain_info Callback for "add domain" action to generate the information line
hansel_domain_hansel_action_types Implements hook_hansel_action_types().
hansel_domain_hansel_cache_parts_alter Implements hook_hansel_cache_parts_alter().
hansel_domain_hansel_switch_types Implements hook_hansel_switch_types().
hansel_domain_switch_domain_id_compare Callback for "domain id" switch to compare a given value.
hansel_domain_switch_subdomain_compare Callback for "subdomain" switch to compare a given value.