function tripal_core_node_toc_form

2.x tripal_core.toc.inc tripal_core_node_toc_form($form, &$form_state, $node)
3.x tripal_core.toc.inc tripal_core_node_toc_form($form, &$form_state, $node)
1 string reference to 'tripal_core_node_toc_form'
tripal_core_menu in tripal_core/tripal_core.module
Implements hook_menu(). Defines all menu items needed by Tripal Core

File

tripal_core/includes/tripal_core.toc.inc, line 6

Code

function tripal_core_node_toc_form($form, &$form_state, $node) {

  // Get info about this content type
  $all_types = node_type_get_types();
  $type_info = $all_types[$node->type];

  $form["#tree"] = TRUE;

  $form["instructions"] = array(
    '#type' => 'fieldset',
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#title' => 'Instructions',
  );
  $admin_link = l(
  $type_info->name . " TOC administrative page", 
  "admin/tripal/chado/" . $type_info->module . "/" . $node->type . "toc", 
  array('attributes' => array('target' => '_blank'))
  );
  $form["instructions"]["main"] = array(
    '#markup' => '<p>' . t("Below is a list of the titles of
      content panes that can appear on this page.  These titles appear in the
      the following order in the Table of Contents (TOC). You may rename
      the titles or drag and drop them to change the order.  <b>Any changes will
      only apply to this page</b>. If you would like to make changes apply to multiple
      pages of the same type, please visit the $admin_link. ") . '</p>' .
      '<p>' . t('The list below shows all possible content panes that can appear.
      However, those without content are automatically hidden and do not
      appear in the TOC.' . '</p>'),
  );

  $form['node'] = array(
    '#type' => 'value',
    '#value' => $node,
  );

  // Get the content array for this node, then pass it through the
  // tripal_core_node_view_alter which generates the TOC.  After that
  // we can use the $build array to build the form. We have to add
  // a 'tripal_toc_mode' to the $node because we need to give the mode
  // to the tripal_core_node_view_build_toc function.
  $node->tripal_toc_mode = 'manage_node';
  node_build_content($node);
  $build = $node->content;
  $build["#node"] = $node;
  tripal_core_node_view_alter($build);

  // Iterate through the built items and add form elemetns for each one.
  foreach (element_children($build) as $key) {
    $element = $build[$key];

    if (array_key_exists('#tripal_toc_id', $element)) {
      $toc_id = $element['#tripal_toc_id'];
      $toc_title = $element['#tripal_toc_title'];
      $toc_weight = $element['#weight'];
      $toc_hide = $element['#hide'];

      // If this element is a link then we don't want to allow the user
      // to change the title as the link title is changed by using the
      // interface that created the link.
      $is_link = array_key_exists('#is_link', $element) ? $element['#is_link'] : FALSE;
      if (!$is_link) {
        $form['toc_items'][$toc_id]['title'] = array(
          '#type' => 'textfield',
          '#default_value' => $toc_title,
        );
      }
      else {
        $form['toc_items'][$toc_id]['title'] = array(
          '#markup' => '<i>link title:</i> ' . $toc_title,
          '#value' => $toc_title,
        );
      }
      $form['toc_items'][$toc_id]['hide'] = array(
        '#type' => 'checkbox',
        '#default_value' => $toc_hide,
      );
      $form['toc_items'][$toc_id]['weight'] = array(
        '#type' => 'textfield',
        '#default_value' => $toc_weight,
        '#attributes' => array(
          'class' => array('tripal-node-toc-items-weights'),
        ),
        '#size' => 5,
      );
    }
  }
  $form['toc_items']['#theme'] = 'tripal_node_toc_items_table';

  $form['submit'] = array(
    '#type' => 'submit',
    '#name' => 'toc_submit',
    '#value' => t('Submit'),
  );
  $form['unset'] = array(
    '#type' => 'submit',
    '#name' => 'toc_unset',
    '#value' => t('Unset Node Customizations'),
  );

  // Check to see if this node's TOC is specifically being managed.
  $sql = "SELECT count(*) FROM {tripal_toc} where nid = :nid";
  $managed_items = db_query($sql, array(':nid' => $node->nid))->fetchField();

  if ($managed_items > 0) {
    $form['is_managed'] = array(
      '#markup' => '<p><font color="red">' .
        t('This page currently has customiations to the TOC.</font> This means
        that any customzations for the content type are overriden. Click the
        "Unset Node Customizations" button above to remove page-level
        customizations and default to the content type settings.') . '</p>',
    );
  }


  return $form;
}