我有Drupal 7站点。它具有自定义内容类型"产品"。它有20个字段。我想控制此内容类型的添加/编辑表单的UI。
我在sites/all/modules下创建了一个模块。
- admin_product
-admin_product.info
-admin_product.module
-admin_product.module
<?php
function admin_product_theme($existing, $type, $theme, $path){
return array(
'product_node_form' => array(
'arguments' => array(
'form' => NULL,
),
'path' => drupal_get_path('theme', 'myTheme').'/templates/forms',
'template' => 'product-node-form',
'render element' => 'form',
)
);
}
在模板-sites/all/themes/myTheme/templates/forms/product-node-form.tpl.php
-产品型号:form.tpl.php
<?php
echo drupal_render_children($form);
echo 'hello template'; // just to test
?>
模板不会被渲染。
如何控制表单的UI
非常感谢您的帮助。
我认为您所需要的只是字段组模块。在这个模块的帮助下,你可以将所有字段分组(如div、tab等)。其余的内容可以用CSS制作。
另一种方法是使用hook_form_FORM_ID_alter()
钩子,或者更具体地说,hook_form_node_form_alter()
来更改您的表单
无论如何,在Drupal 7中,Form API与Theme API不同,您提供的代码毫无意义:)很抱歉:)
如果您要添加的主题不是网站的默认管理主题,那么该模板将不会在管理区域中被选中。
您必须将此代码添加到自定义模块中,或者基于管理主题创建一个子主题(例如,Seven),然后选择它作为您的管理主题并将代码放在那里。
这里有很好的解释:https://drupal.stackexchange.com/questions/33253/how-do-you-theme-a-content-types-create-edit-form-in-drupal-7