Drupal 7 - 如何在其他页面上显示节点/添加/某种形式的表单? [英] Drupal 7 - How to display node/add/sometype form on another page?

查看:135
本文介绍了Drupal 7 - 如何在其他页面上显示节点/添加/某种形式的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整个问题如下:

假设我们有项目,项目可以有出价,项目可以有问题和问题可以回答。

Lets say we have Items, Items can have Bids, Items can have Questions and Question can have Answer.

当显示项目时,还应显示与此项目相关联的所有内容。另外取决于角色,应该显示某些形式的出价,问题和重播答案。

When an Item is displayed, all content associated with this Item should also be displayed. Additionally depending on roles, certain forms to make Bids, ask Questions and replay Answers should be display.

如何实现?我应该为每种类型分别设置节点类型吗?或者我应该像问题和答案一样处理一些子类型作为评论?我应该使用一些知名的模块吗?

How to achieve this? Should I have separate node type for each type? Or should I treat some subtypes like Questions and Answers as comments? Should I use some well-known modules for this?

我正在使用Drupal 7,我尝试编写一个自定义模块,但没有正常工作。

I am using Drupal 7 and I tried to write a custom module but I didn't get it working properly.

推荐答案

要获取节点编辑表单,您需要包括 node.pages.inc

To get a node edit form, you need to include node.pages.inc.

<?php
  // required for Drupal 6
  module_load_include('inc', 'node', 'node.pages'); 
  // which nodeform you want
  $node_type = 'YOURNODETYPE';
  $form_id = $node_type . '_node_form';
  // maybe add current users info
  global $user;
  // create a blank node
  $node = array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => $node_type,
  );
  // Invoke hook_nodapi and hook_node
  node_object_prepare($node);
  // Or you can also use an exiting node, for example
  // $node = node_load(123);
  // and the display the form:
  $output = drupal_get_form($form_id, $node);
?>

这篇关于Drupal 7 - 如何在其他页面上显示节点/添加/某种形式的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆