You are here

function oa_section_context_form_node_form_alter in Open Atrium Core 7.2

Implements hook_form_alter

Instantiates the default value for the field 'oa_section_ref' from session context if it exists.

File

modules/oa_section_context/oa_section_context.module, line 68
Provides hook implementations and functionality for oa_section_context.

Code

function oa_section_context_form_node_form_alter(&$form, &$form_state, $form_id) {
  if (!empty($_GET['oa_section_ref']) && is_numeric($_GET['oa_section_ref'])) {
    $section = $_GET['oa_section_ref'];
  }
  elseif (!empty($_SESSION[OA_SESSION_SECTION])) {
    $section = $_SESSION[OA_SESSION_SECTION];
  }
  if (!empty($form[OA_SECTION_FIELD][LANGUAGE_NONE]['#options']) && empty($form[OA_SECTION_FIELD][LANGUAGE_NONE]['#default_value']) && !empty($section) && array_key_exists($section, $form[OA_SECTION_FIELD][LANGUAGE_NONE]['#options'])) {
    $form[OA_SECTION_FIELD][LANGUAGE_NONE]['#default_value'] = $section;
  }
}