简体   繁体   English

drupal form alter从内容创建/编辑表单中删除cck字段

[英]drupal form alter remove cck field from content create/edit form

从内容类型的创建/编辑表单页面中删除cck字段显示的代码是什么?

Set the " #access " field to " 0 " or " FALSE ". 将“ #access ”字段设置为“ 0 ”或“ FALSE ”。

For example, this removes the "Site mission" field from the site informations page: 例如,这将从站点信息页面中删除“站点任务”字段:

function example_form_system_site_information_settings_alter(&$form, &$form_state){
 $form['site_mission']['#access'] = 0;
}

(where "example" is the name of a custom module) (其中“example”是自定义模块的名称)


Another example, this time it removes the Sticky option from add/edit page form: 另一个例子,这次它从添加/编辑页面表单中删除Sticky选项:

function example_form_page_node_form_alter(&$form, &$form_state){
 $form['options']['sticky']['#access'] = 0;
}

You probably know that already, but you will need to know the id (and the structure) of the form you wish to alter. 您可能已经知道了,但您需要知道要更改的表单的ID(和结构)。

Most of the time, hook_form_THEID_alter(&$form, &$form_state) is the good place to modify a specific form, however some fields are created after this hook is called, so in such cases, you need to use the generic hook_form_alter(&$form, $form_state, $form_id) instead. 大多数情况下, hook_form_THEID_alter(&$form, &$form_state)是修改特定表单的好地方,但是在调用此挂钩之后会创建一些字段,所以在这种情况下,需要使用通用的hook_form_alter(&$form, $form_state, $form_id)


If you don't know the structure or even the form id (and don't want to install the Devel module ), you could use this snipplet, so that when you're viewing the page you want to modify, it will display the form id and its structure at the top of the page. 如果您不知道结构甚至表单ID(并且不想安装Devel模块 ),您可以使用此snipplet,这样当您查看要修改的页面时,它将显示表单ID及其在页面顶部的结构。

function example_form_alter(&$form, $form_state, $form_id){
 echo "<h1>Form ID: $form_id</h1>";
 echo "Form Structure: <pre>".print_r($form, true)."</pre>";
}

(where "example" is the name of your custom module). (其中“example”是自定义模块的名称)。


By the way, if you're just trying to prevent regular users from editing admin-only fields, you could simply use the Field Permissions module instead. 顺便说一句,如果您只是试图阻止普通用户编辑仅管理员字段,您可以简单地使用字段权限模块

检查此片段http://drupal.org/node/336355#comment-1192845并使用之前评论中描述的内容['#access'] = FALSE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM