Drupal 7 中的节点/内容类型不显示表单

发布于 2024-12-22 17:11:48 字数 1275 浏览 3 评论 0原文

我正在尝试在 drupal 中创建节点/内容类型,因此我至少有一个 .info、.install 和 .module 文件。

该模块创建得很好,我可以从模块管理页面启用/禁用它,而且,Drupal 能够将该模块识别为内容类型,并且当我在内容菜单中单击“添加内容”时它会出现。

一切正常,但它不显示表单元素,而是直接从 在此处输入图像描述

表单元素代码 开始下面列出:

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

 $form['title']= array( 
    '#type' => 'textfield',  
    '#title' => check_plain($type->title_label),  
    '#default_value' => !empty($node->title) ? $node->title : '',  
    '#required' => TRUE,  
    '#weight' => -5, 
  ); 

  $form['field1'] = array( 
    '#type' => 'textfield',  
    '#title' => t('Custom field'),  
    '#default_value' => $node->field1,  
    '#maxlength' => 127, 
  ); 
  $form['selectbox'] = array( 
    '#type' => 'select',  
    '#title' => t('Select box'),  
    '#default_value' => $node->selectbox,  
    '#options' => array( 
      1 => 'Option A',  
      2 => 'Option B',  
      3 => 'Option C', 
    ),  
    '#description' => t('Choose an option.'), 
  ); 
return $form; 
}

任何人都可以告诉我出了什么问题

P.S:仅供参考:在我的 .install 文件中,仅存在安装和卸载挂钩函数。我尚未创建数据库表,此内容类型是我创建内容类型 UI 的演练,不一定是完整的 UI。

I am attempting to create a node/content type in drupal, accordingly I have a .info, .install and .module file at minimum.

The module is created fine and I am able to enable/disable it from the module administration page, also, Drupal is able to recognize this module as a content type and it appears when I click 'Add content' in the Content menu.

Everything works fine, but it does not show the form elements, rather it starts directly at enter image description here

The form element code is listed below:

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

 $form['title']= array( 
    '#type' => 'textfield',  
    '#title' => check_plain($type->title_label),  
    '#default_value' => !empty($node->title) ? $node->title : '',  
    '#required' => TRUE,  
    '#weight' => -5, 
  ); 

  $form['field1'] = array( 
    '#type' => 'textfield',  
    '#title' => t('Custom field'),  
    '#default_value' => $node->field1,  
    '#maxlength' => 127, 
  ); 
  $form['selectbox'] = array( 
    '#type' => 'select',  
    '#title' => t('Select box'),  
    '#default_value' => $node->selectbox,  
    '#options' => array( 
      1 => 'Option A',  
      2 => 'Option B',  
      3 => 'Option C', 
    ),  
    '#description' => t('Choose an option.'), 
  ); 
return $form; 
}

Can anybody tell me what's wrong

P.S: Just F.Y.I: In my .install file, there exists only install and uninstall hook functions. I have yet to create DB tables, this content type is a walkthrough for me to create content type UI and not necessarily a full blown UI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的快感 2024-12-29 17:11:48

Drupal 的钩子系统使用小写字母和小写字母来动态加载模块函数。

<module name>_<hook_name>

尝试像这样声明你的函数:

function new_node_form($node, &$form_state) {
...

Drupal's hook system uses lower cases and under scores to dynamically load module functions.

<module name>_<hook_name>

Try declaring your function like this:

function new_node_form($node, &$form_state) {
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文