节点/添加和节点/编辑页面的不同表单覆盖?

时间:2013-04-19 17:24:58

标签: drupal-7 drupal-forms

Hia的

我在自定义模块中使用以下内容来自定义我的BABY内容类型的节点/添加/宝贝页面上的表单,但我想在节点/ nid / edit页面上对此页面稍作修改对于婴儿内容类型。这有可能吗?

<code>
<?php
function concept_theme() {
  return array(
    'baby_node_form' => array(
      'arguments' => array(
          'form' => NULL,
      ),
      'template' => 'templates/baby-node-form',
      'render element' => 'form',
    ),
  );
}
?>
</code>

谢谢你

2 个答案:

答案 0 :(得分:2)

在template.php中

function my_theme_name_theme($existing, $type, $theme, $path)
$hooks['baby_node_form']=array(
    'render element'=>'form',
    'template'      =>'templates/node--baby-edit',
);
return $hooks;
}

在节点 - baby-edit.tpl.php

隐藏这样的字段:

<?php hide($form['title']); ?>

操纵这样的字段:

<?php print render($form['field_image']); ?>

使用它来打印所有/其他内容:

<?php print drupal_render_children($form); ?>

清除缓存。

答案 1 :(得分:1)

您可以通过实现此挂钩来更改节点创建表单, 类似的东西:

hook_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'node_baby_form') {
     //do modification to form array $form
  }
}

或者如果您的节点是由hook_node_info定义的(我认为不是这种情况),只需更改hook_form()中的元素