You are here

spaces_user.module in Spaces 7

File

spaces_user/spaces_user.module
View source
<?php

/**
 * Implements hook_init().
 */
function spaces_user_init() {
  if (arg(0) === 'user' && arg(1) !== 'autocomplete') {
    global $user;
    $uid = is_numeric(arg(1)) ? arg(1) : $user->uid;
    if ($uid) {
      spaces_init_space('user', $uid);
    }
  }
}

/**
 * Implements hook_permission().
 */
function spaces_user_permission() {
  return array(
    'configure own user space' => array(
      'title' => t('configure own user space'),
      'description' => t('TODO Add a description for \'configure own user space\''),
    ),
  );
}

/**
 * Implements hook_ctools_plugin_api().
 */
function spaces_user_ctools_plugin_api($module, $api) {
  if ($module == 'spaces' && $api == 'plugins') {
    return array(
      'version' => 3,
    );
  }
}

/**
 * Implements hook_spaces_plugins().
 */
function spaces_user_spaces_plugins() {
  $plugins = array();
  $plugins['space_user'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'spaces_user') . '/plugins',
      'file' => 'space_user.inc',
      'class' => 'space_user',
      'parent' => 'space_type',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_spaces_registry().
 */
function spaces_user_spaces_registry() {
  return array(
    'types' => array(
      'user' => array(
        'title' => t('User space'),
        'plugin' => 'space_user',
        'path' => 'user/%user',
      ),
    ),
  );
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * For user_profile_form
 */
function spaces_user_form_user_profile_form_alter(&$form, &$form_state) {
  module_load_include('inc', 'spaces', 'spaces.admin');
  $presets = spaces_preset_load(NULL, 'user');
  if (count($presets) === 1) {
    $form['spaces_preset_user'] = array(
      '#type' => 'value',
      '#value' => key($presets),
    );
  }
  else {
    if (count($presets) > 1) {
      $form = array();
      $form['spaces_preset'] = spaces_preset_form($presets, 'user');
    }
  }
}

/**
 * Implements hook_user_insert().
 */
function spaces_user_user_insert(&$edit, $account, $category) {

  // Save preset values
  if (!empty($edit['spaces_preset_user'])) {
    $space = spaces_load('user', $account->uid);
    if ($space
      ->activate()) {
      $space->controllers->variable
        ->set('spaces_preset_user', $edit['spaces_preset_user']);
    }
  }
}

/**
 * Implements hook_user_update().
 */
function spaces_user_user_update(&$edit, $account, $category) {

  // Save preset values
  if (!empty($edit['spaces_preset_user'])) {
    $space = spaces_load('user', $account->uid);
    if ($space
      ->activate()) {
      $space->controllers->variable
        ->set('spaces_preset_user', $edit['spaces_preset_user']);
    }
  }
}

/**
 * Implements hook_form_alter() for spaces_features_form().
 * Disallow site_frontpage var from being customizable within a user space.
 */
function spaces_user_form_spaces_features_form_alter(&$form, &$form_state) {
  $space = spaces_get_space();
  if ($space && $space->type === 'user' && !empty($form['site_frontpage'])) {
    unset($form['site_frontpage']);
  }
}