qwertmax qwertmax - 7 months ago 10
PHP Question

how to show edit form on the "node/[nid]" page?

I have a content type (budget), it is a custom content type

function budget_node_info() {
return array(
'budget' => array(
'base' => 'budget',
'name' => t('Budget'),
'description' => t('Represents individual budget.'),
'title_label' => t('Budget Name'),
'locked' => TRUE
)
);
}


also I have the form function

function budget_form($node, $form_state) {
drupal_add_library('system', 'ui.tabs');
drupal_add_library('budget', 'highcharts');
drupal_add_js(drupal_get_path('module', 'budget') . '/js/budget_base.js');
drupal_add_js(drupal_get_path('module', 'budget') . '/js/' . $node->type . '.js');

$form = node_content_form($node, $form_state);
$config = variable_get($node->type);


I want to show the edit form on the node view page (I want to show form from node/[nid]/edit to node/[nid])?

I tried next:

function budget_node_view($node, $view_mode, $langcode){
$node->content['edit-form'] = array(
'#markup' => render(drupal_get_form('budget_form', $node)),
'#weight' => 10,
);
}


also I tried

function budget_node_view($node, $view_mode, $langcode){
$node->content['edit-form'] = array(
'#markup' => render(budget_form($node, array())),
'#weight' => 10,
);
}


2nd version show form but without any js or css loaded.

What am I doing wrong?

Answer

I used function node_page_edit($node) and seems like it works

function wp_budget_node_view($node, $view_mode, $langcode){
  module_load_include('inc', 'node', 'node.pages');
  $node->content['edit-form'] = array(
    '#markup' => render(node_page_edit($node)),
    '#weight' => 10,
  );
}

also for new (empty) form you should use node_add function function node_add($type