drupal_get_form is not passing along node array

Posted by ElectronicBlacksmith on Stack Overflow See other posts from Stack Overflow or by ElectronicBlacksmith
Published on 2010-05-12T19:25:46Z Indexed on 2010/05/14 9:34 UTC
Read the original article Hit count: 349

Filed under:
|

I have not been able to get drupal_get_form to pass on the node data. Code snippets are below. The drupal_get_form documentation (api.drupal.org) states that it will pass on the extra parameters. I am basing the node data not being passed because (apparently) $node['language'] is not defined in hook_form which causes $form['qqq'] not to be created and thus the preview button shows up.

My goal here is that the preview button show up using path "node/add/author" but doesn't show up for "milan/author/add". Any alternative methods for achieving this goal would be helpful but the question I want answered is in the preceding paragraph. Everything I've read indicates that it should work.

This menu item

 $items['milan/author/add'] = array(
    'title' => 'Add Author',
    'page callback' => 'get_author_form',
    'access arguments' => array('access content'),
    'file' => 'author.pages.inc',
  );

calls this code

function get_author_form() {
  //return node_form(NULL,NULL);
  //return drupal_get_form('author_form');
  return author_ajax_form('author');
}

function author_ajax_form($type) {
  global $user;
  module_load_include('inc', 'node', 'node.pages');

  $types = node_get_types();
  $type = isset($type) ? str_replace('-', '_', $type) : NULL;
  // If a node type has been specified, validate its existence.
  if (isset($types[$type]) && node_access('create', $type)) {
    // Initialize settings:
    $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => 'bbb','bbb' => 'TRUE');
    $output = drupal_get_form($type .'_node_form', $node);
  }

  return $output;
}

And here is the hook_form and hook_form_alter code

function author_form_author_node_form_alter(&$form, &$form_state) {
    $form['author']=NULL;
    $form['taxonomy']=NULL;
    $form['options']=NULL;
    $form['menu']=NULL;
    $form['comment_settings']=NULL;
    $form['files']=NULL;
    $form['revision_information']=NULL;
    $form['attachments']=NULL;
    if($form["qqq"]) {
      $form['buttons']['preview']=NULL;
    }
}

function author_form(&$node) {
  return make_author_form(&$node);
}


function make_author_form(&$node) {
  global $user;
  $type = node_get_types('type', $node);

  $node = author_make_title($node);
  drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t($node->title), 'node/' . $node->nid)));


  $form['authorset'] = array(
      '#type' => 'fieldset',
      '#title' => t('Author'),
      '#weight' => -50,
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );

  $form['author_id'] = array(
    '#access' => user_access('create pd_recluse entries'),
    '#type' => 'hidden',
    '#default_value' => $node->author_id,
    '#weight' => -20
  );



  $form['authorset']['last_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name'),
    '#maxlength' => 60,
    '#default_value' => $node->last_name
  );

  $form['authorset']['first_name'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name'),
    '#maxlength' => 60,
    '#default_value' => $node->first_name
  );

  $form['authorset']['middle_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Middle Name'),
    '#maxlength' => 60,
    '#default_value' => $node->middle_name
  );

  $form['authorset']['suffix_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Suffix Name'),
    '#maxlength' => 14,
    '#default_value' => $node->suffix_name
  );

  $form['authorset']['body_filter']['body'] = array(
      '#access' => user_access('create pd_recluse entries'),
      '#type' => 'textarea',
      '#title' => 'Describe Author',
      '#default_value' => $node->body,
      '#required' => FALSE,
      '#weight' => -19
    );


  $form['status'] = array(
    '#type' => 'hidden',
    '#default_value' => '1'
  );

  $form['promote'] = array(
    '#type' => 'hidden',
    '#default_value' => '1'
  );

  $form['name'] = array(
    '#type' => 'hidden',
    '#default_value' => $user->name
  );

  $form['format'] = array(
    '#type' => 'hidden',
    '#default_value' => '1'
  );


  // NOTE in node_example there is some addition code here not needed for this simple node-type
  $thepath='milan/author';
  if($_REQUEST["theletter"]) {
    $thepath .= "/" . $_REQUEST["theletter"];
  }

  if($node['language']) {
    $thepath='milan/authorajaxclose';
    $form['qqq'] = array(
      '#type' => 'hidden',
      '#default_value' => '1'
    );
  }

  $form['#redirect'] = $thepath;

  return $form;
}

That menu path coincides with this theme (PHPTemplate)

    

© Stack Overflow or respective owner

Related posts about drupal-6

Related posts about drupal-module