Skip to content
totem.profile 10.7 KiB
Newer Older
Nate Mow's avatar
Nate Mow committed
<?php
/**
 * @file
 * totem.profile
 */
Nate Mow's avatar
Nate Mow committed

// Hook implementations.
/**
 * Implements hook_form_FORM_ID_alter().
 */
function totem_form_install_configure_form_alter(&$form, &$form_state, $form_id) {

  $mail = variable_get('site_mail', 'admin@' . $_SERVER['HTTP_HOST']);
Nate Mow's avatar
Nate Mow committed

  $form['site_information']['#collapsible']
      = $form['admin_account']['#collapsible']
      = $form['server_settings']['#collapsible']
      = $form['update_notifications']['#collapsible']
      = TRUE;
Nate Mow's avatar
Nate Mow committed

  $form['site_information']['#title'] = st('Community information');

  $form['site_information']['site_name']['#title'] = st('Name');
  $form['site_information']['site_name']['#weight'] = 10;
  $form['site_information']['site_name']['#default_value'] = variable_get('site_name');

  $form['site_information']['site_slogan'] = array(
    '#type' => 'textfield',
    '#title' => st('Tagline'),
    '#description' => st(''),
    '#default_value' => variable_get('site_slogan'),
    '#required' => FALSE,
    '#weight' => 30,
  );

  $form['site_information']['site_mail']['#title'] = st('Email address');
  $form['site_information']['site_mail']['#weight'] = 30;
  $form['site_information']['site_mail']['#default_value'] = $mail;

  $form['admin_account']['#title'] = st('Community administrator');
  $form['admin_account']['account']['name']['#default_value'] = $mail;
  $form['admin_account']['account']['mail']['#title'] = st('Email address');
  $form['admin_account']['account']['mail']['#default_value'] = $mail;
  // Force standard password field (vs. pass w/confirm and strength).
  $form['admin_account']['account']['pass']['#type'] = 'password';
Nate Mow's avatar
Nate Mow committed
  $form['admin_account']['account']['pass']['#title'] = st('Password');

  // Force username to hidden unique id mail will be copied to name field
  // in hook_user_presave.
Nate Mow's avatar
Nate Mow committed
  $form['admin_account']['account']['name'] = array(
    '#type' => 'hidden',
    '#value' => $form['admin_account']['account']['mail']['#default_value'],
  );

  $form['admin_account']['update_status_module'] = $form['update_notifications']['update_status_module'];

  unset($form['update_notifications']);

  // Add extra submit handlers.
Nate Mow's avatar
Nate Mow committed
  $form['#submit'][] = 'totem_form_install_configure_form_submit';
}
/**
 * Custom submit handler for settings form.
 */
function totem_form_install_configure_form_submit($form, &$form_state) {

  global $user;

  // Save new account info.
Nate Mow's avatar
Nate Mow committed
  $userinfo = array(
    'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Administrator'))),
    'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Administrator'))),
  );

  $user = user_save($user, $userinfo);

  // Update system variables.
Nate Mow's avatar
Nate Mow committed
  variable_set('site_slogan', filter_xss_admin($form_state['values']['site_slogan']));
}
/**
 * Implements hook_install_tasks().
 */
function totem_install_tasks($install_state) {

  $tasks = array(
    '_totem_install_menus' => array(),
    '_totem_install_blocks' => array(),
Nate Mow's avatar
Nate Mow committed
    // '_totem_install_samples' => array(
    //   'display_name' => st('Install samples'),
    // ),
Nate Mow's avatar
Nate Mow committed
    '_totem_install_rebuilds' => array(
Nate Mow's avatar
Nate Mow committed
      'display_name' => st('Build permissions'),
Nate Mow's avatar
Nate Mow committed
    ),
  );

  return $tasks;
}

// Installation tasks.
/**
 * TODO.
 */
Nate Mow's avatar
Nate Mow committed
function _totem_install_menus() {

  // Only install menus if no custom client-centric mod is enabled.
  $profile_custom_mod = variable_get('totem_custom');
  if (!empty($profile_custom_mod)) {
    return;
  }

  // Menus are added in totem.profile, after all Features mods have
  // been installed.
  $profile_intall_vars = variable_get('totem_install_temp_vars');

  $items_footer = array(
    array(
      'link_title' => st('Featured Communities'),
      'link_path' => 'communities/featured',
      'menu_name' => 'footer-menu',
      'weight' => 4,
    ),
    array(
      'link_title' => st('About'),
      'link_path' => 'node/' . $profile_intall_vars['nid_about'],
      'menu_name' => 'footer-menu',
      'weight' => 5,
    ),
    array(
      'link_title' => st('Privacy Policy'),
      'link_path' => 'node/' . $profile_intall_vars['nid_privacy'],
      'menu_name' => 'footer-menu',
      'weight' => 6,
    ),
    array(
      'link_title' => st('Terms of Use'),
      'link_path' => 'node/' . $profile_intall_vars['nid_terms'],
      'menu_name' => 'footer-menu',
      'weight' => 7,
    ),
  );

  // Delete baseline Footer menu links.
  menu_delete_links('footer-menu');

  // Add Footer menu items.
  foreach ($items_footer as $key => &$meta) {
    menu_link_save($meta);
  }

  $items_main = array(
    array(
      'link_title' => st('Home'),
      'link_path' => '<front>',
      'menu_name' => 'main-menu',
      'weight' => 3,
    ),
    array(
      'link_title' => st('Communities'),
      'link_path' => 'user/modal/login',
      'menu_name' => 'main-menu',
      'weight' => 4,
    ),
    array(
      'link_title' => st('Members'),
      'link_path' => 'user/modal/login',
      'menu_name' => 'main-menu',
      'weight' => 5,
    ),
    array(
      'link_title' => st('Discussions'),
      'link_path' => 'user/modal/login',
      'menu_name' => 'main-menu',
      'weight' => 6,
    ),
    array(
      'link_title' => st('Events'),
      'link_path' => 'user/modal/login',
      'menu_name' => 'main-menu',
      'weight' => 7,
    ),
    array(
      'link_title' => st('Media'),
      'link_path' => 'user/modal/login',
      'menu_name' => 'main-menu',
      'weight' => 8,
    ),
    array(
      'link_title' => st('Resources'),
      'link_path' => 'user/modal/login',
      'menu_name' => 'main-menu',
      'weight' => 9,
    ),
  );

  // Delete baseline Main menu links.
  menu_delete_links('main-menu');

  // Add Main menu items.
  foreach ($items_main as $key => &$meta) {
    menu_link_save($meta);
  }

  $items_community = array(
    array(
      'link_title' => st('Home'),
      'link_path' => 'user',
      'menu_name' => 'menu-community-menu',
      'weight' => 3,
    ),
    array(
      'link_title' => st('Communities'),
      'link_path' => 'communities',
      'menu_name' => 'menu-community-menu',
      'weight' => 4,
    ),
    array(
      'link_title' => st('Members'),
      'link_path' => 'members',
      'menu_name' => 'menu-community-menu',
      'weight' => 5,
    ),
    array(
      'link_title' => st('Discussions'),
      'link_path' => 'topics',
      'menu_name' => 'menu-community-menu',
      'weight' => 6,
    ),
    array(
      'link_title' => st('Events'),
      'link_path' => 'events',
      'menu_name' => 'menu-community-menu',
      'weight' => 7,
    ),
    array(
      'link_title' => st('Media'),
      'link_path' => 'media',
      'menu_name' => 'menu-community-menu',
      'weight' => 8,
    ),
    array(
      'link_title' => st('Resources'),
      'link_path' => 'resources',
      'menu_name' => 'menu-community-menu',
      'weight' => 9,
      'expanded' => TRUE,
    ),
  );

  // Delete baseline Community menu links.
  menu_delete_links('menu-community-menu');

  // Add Community menu items.
  foreach ($items_community as $key => &$meta) {
    menu_link_save($meta);
  }

  // Update the menu router information.
  menu_rebuild();
}
/**
 * TODO.
 */
Nate Mow's avatar
Nate Mow committed
function _totem_install_blocks() {

  // Get the current themes.
  $theme_default = variable_get('theme_default');
  $theme_admin = variable_get('admin_theme');

  // Update titles.
  db_update('block')
    ->fields(array('title' => '<none>'))
    ->condition('module', 'totem_common', '!=')
    ->execute();

  // Unassign blocks from admin theme.
  db_update('block')
    ->fields(array('region' => BLOCK_REGION_NONE))
    ->condition('module', 'system', '!=')
    ->condition('delta', 'main', '!=')
    ->condition('theme', $theme_admin)
    ->execute();
}
/**
 * TODO.
 */
Nate Mow's avatar
Nate Mow committed
function _totem_install_samples() {

  $users = array(
    array(
      'name' => 'irorginator@gmail.com',
      'pass' => 'Tester1234',
      'mail' => 'irorginator@gmail.com',
      'init' => 'irorginator@gmail.com',
      'status' => 1,
      'access' => REQUEST_TIME,
      'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Owner'))),
      'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Community'))),
    ),
    array(
      'name' => 'iaremanager@gmail.com',
      'pass' => 'Tester1234',
      'mail' => 'iaremanager@gmail.com',
      'init' => 'iaremanager@gmail.com',
      'status' => 1,
      'access' => REQUEST_TIME,
      'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Manager'))),
      'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Community'))),
    ),
    array(
      'name' => 'iareuser@gmail.com',
      'pass' => 'Tester1234',
      'mail' => 'iareuser@gmail.com',
      'init' => 'iareuser@gmail.com',
      'status' => 1,
      'access' => REQUEST_TIME,
      'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Member'))),
      'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Community'))),
    ),
  );

  foreach ($users as $meta) {
    $account = user_save(NULL, $meta);
Nate Mow's avatar
Nate Mow committed

    db_insert('users_roles')
      ->fields(array('uid' => $account->uid, 'rid' => DRUPAL_AUTHENTICATED_RID))
      ->execute();
  }

  // Add community nodes for uid:2
  $nodes = array(
    0 => 'Open Community',
    1 => 'Restricted Community',
    2 => 'Closed Community',
  );

  foreach ($nodes as $status => $title) {
    $node = new stdClass();
    $node->type = 'community';
    $node->uid = 2;
    $node->language = LANGUAGE_NONE;
    $node->title = $title;
    $node->body[$node->language][0]['value'] = '';
    $node->body[$node->language][0]['format'] = 'filtered_html';
    $node->field_community_status[$node->language][0]['value'] = $status;
    $node->field_community_featured[$node->language][0]['value'] = 1;

    @node_save($node);

    // Add new field_community values for uid:2, 3, 4.
Nate Mow's avatar
Nate Mow committed
    $u = user_load(2);
    _totem_common_set_field_entityreference_values('user', $u, 'field_community', array($node->nid));

    $u = user_load(3);
    _totem_common_set_field_entityreference_values('user', $u, 'field_community', array($node->nid));

    // Grant "manager" perms to this $account.
    $record = array(
      'nid' => $node->nid,
      'gid' => $u->uid,
      'realm' => 'totem_user_node_manager',
      'grant_view' => 1,
      'grant_update' => 1,
      'grant_delete' => 0,
    );
Nate Mow's avatar
Nate Mow committed

    drupal_write_record('node_access', $record);
Nate Mow's avatar
Nate Mow committed

    $u = user_load(4);
    _totem_common_set_field_entityreference_values('user', $u, 'field_community', array($node->nid));
  }
}
/**
 * TODO.
 */
Nate Mow's avatar
Nate Mow committed
function _totem_install_rebuilds() {

  // Remove temp install var.
  variable_del('totem_install_temp_vars');

  // Grant new administrator role all permissions.
  user_role_grant_permissions(3, array_keys(module_invoke_all('permission')));

  // Rebuild the node access database.
  node_access_rebuild(FALSE);

  drupal_set_message(t('@site_name installed successfully!', array('@site_name' => variable_get('site_name'))));
}