You are here

function sheetnode_form in Sheetnode 6

Same name and namespace in other branches
  1. 5 sheetnode.module \sheetnode_form()
  2. 7.2 sheetnode.module \sheetnode_form()
  3. 7 sheetnode.module \sheetnode_form()

Implementation of hook_form().

File

./sheetnode.module, line 95

Code

function sheetnode_form(&$node, $form_state) {
  $type = node_get_types('type', $node);

  // Generate the default title and body.
  $form = node_content_form($node, $form_state);

  // SocialCalc sheet.
  if (!empty($node->nid)) {
    $value = $node->sheetnode['value'];
    $nid = $node->nid;
  }
  else {
    if (!empty($node->clone_from_original_nid)) {

      // support node_clone.module
      $original_node = node_load($node->clone_from_original_nid);
      $value = $original_node->sheetnode['value'];
      $nid = $node->clone_from_original_nid;
    }
    else {
      $value = '';
      $nid = NULL;
    }
  }
  $output = _sheetnode_inject('sheetnode-' . (empty($node->nid) ? 'new' : $node->nid), 'sheetnode', $value, 'edit-sheetnode-value', array(
    'entity-type' => 'node',
    'oid' => $nid,
  ));
  $form['sheetnode'] = array(
    '#tree' => TRUE,
    '#value' => $output,
    '#weight' => -1,
    'value' => array(
      '#type' => 'hidden',
    ),
  );

  // Template.
  if (user_access('create sheetnode template')) {
    $form['sheetnode']['template'] = array(
      '#type' => 'textfield',
      '#title' => t('Save as template'),
      '#description' => t('When saving this sheet, also keep a copy under the name you specify here. Later, this copy can be used as a template for other sheets.'),
      '#required' => FALSE,
    );
  }
  return $form;
}