oa_section_context.module in Open Atrium Core 7.2
Provides hook implementations and functionality for oa_section_context.
File
modules/oa_section_context/oa_section_context.module
View source
<?php
define('OA_SESSION_SECTION', 'oa_section_id');
function oa_section_get_section_context() {
$menu = menu_get_object();
if (!isset($menu->nid) || !($node = node_load($menu->nid))) {
return isset($_SESSION[OA_SESSION_SECTION]) ? $_SESSION[OA_SESSION_SECTION] : 0;
}
$set_session = 0;
if ($node->type == 'oa_section') {
$set_session = $node->nid;
}
elseif (isset($node->{OA_SECTION_FIELD}[LANGUAGE_NONE][0]['target_id'])) {
$set_session = $node->{OA_SECTION_FIELD}[LANGUAGE_NONE][0]['target_id'];
}
return $set_session;
}
function oa_section_context_init() {
global $user;
if ($user->uid == 0 && !drupal_session_started()) {
return;
}
$set_session = oa_section_get_section_context();
if ($set_session && ($node = node_load($set_session)) && node_access('view', $node)) {
$_SESSION[OA_SESSION_SECTION] = $set_session;
}
elseif (isset($_SESSION[OA_SESSION_SECTION])) {
unset($_SESSION[OA_SESSION_SECTION]);
}
}
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;
}
}
function oa_section_context_entity_property_info() {
$info = array();
$properties =& $info['site']['properties'];
$properties['oa_section_context'] = array(
'label' => t('Current OA section'),
'description' => t('The current Open Atrium Section from context, if exists.'),
'getter callback' => 'oa_section_context_get_properties',
'type' => 'node',
);
return $info;
}
function oa_section_context_get_properties($data = FALSE, array $options, $name) {
if ($section_id = oa_section_get_section_context()) {
return entity_load_single('node', $section_id);
}
}