<?php

function groups_common_form_alter(&$form, &$form_state, $form_id) {

  if ($form_id == 'search_block_form') {
    // remove content selector from search block
    $form['custom_search_types']['#type'] = 'hidden';
    $form['custom_search_types']['#default_value'] = 'o-search_facetapi';
  }
}

/**
 * Implements hook_leaflet_map_info_alter().
 * Disable scrollWheelZoom feature for all leaflet maps.
 *
 * @param unknown $map_info
 */

function groups_common_leaflet_map_info_alter(&$map_info) {
  foreach ($map_info as $map_id => $info) {
    $map_info[$map_id]['settings']['scrollWheelZoom'] = FALSE;
  }
}

/**
 * Implement hook_commons_utility_links_alter()
 *
 * Rename login link link to "Signup or Sign in"
 */

function groups_common_commons_utility_links_alter(&$links) {
  if (isset($links['login'])) {
    $links['login']['title'] = t('Sign up or Login');
  }
  if (isset($links['signup'])) {
    $links['signup']['title'] = t('Sign in');
  }
}

/**
 * Implements hook_element_info_alter()
 *
 * Override filter_process_format.
 *
 * @see _groups_common_filter_process_format()
 */
function groups_common_element_info_alter(&$type) {
  if (isset($type['text_format']['#process'])) {
    foreach ($type['text_format']['#process'] as &$callback) {
      if ($callback === 'filter_process_format') {
        $callback = '_groups_common_filter_process_format';
      }
    }
  }
}

/**
 * Callback to for text_format_alter hooks.
 */
function _groups_common_filter_process_format($element) {
  $element = filter_process_format($element);
  foreach (module_implements('text_format_alter') as $module) {
    $function = $module . '_text_format_alter';
    $function($element);
  }
  return $element;
}

/**
 * Implements hook_libraries_search_paths_alter()
 *
 * Add commons profile libraries to library path as part of the base profile
 * inheritance.
 */
function groups_common_libraries_search_paths_alter(&$searchdir) {
  $profile_commons = drupal_get_path('profile', 'commons');
  $searchdir[] = "$profile_commons/libraries";
}
