You are here

function oa_sections_node_prepare in Open Atrium Core 7.2

Implements hook_node_prpeare().

File

modules/oa_sections/oa_sections.module, line 220

Code

function oa_sections_node_prepare($node) {

  // If we are on the node add form that is specific to this Section type, we
  // take the 'Section type' from the URL and hide the field.
  // We do this in prepare instead of form_alter so not lost during AJAX.
  if (empty($node->nid) && $node->type == 'oa_section') {
    $node->default_menu_hidden = TRUE;
    $node->default_menu_enabled = TRUE;
    if (strpos($_GET['q'], 'node/add/oa-section/') === 0 && ($section_tid = arg(3))) {
      $node->field_oa_section[LANGUAGE_NONE] = array(
        array(
          'tid' => $section_tid,
        ),
      );
      $node->hide_field_oa_section = TRUE;
      $section = taxonomy_term_load($section_tid);
      $values = field_get_items('taxonomy_term', $section, 'field_oa_section_type_menu');
      if (!empty($values[0]['value'])) {
        if ($values[0]['value'] == OA_SECTION_TYPE_MENU_VISIBLE) {
          $node->default_menu_hidden = FALSE;
        }
        elseif ($values[0]['value'] == OA_SECTION_TYPE_MENU_NONE) {
          $node->default_menu_enabled = FALSE;
        }
      }
    }
  }
}