Drupal - 如何禁用“输入格式”节点编辑表单中的字段集
我正在使用 hook_form_alter 禁用一些作者添加或编辑节点的发布选项:
/**
* hook_form_alter ()
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
global $user;
if ($form['#id'] == 'node-form') {
unset($form['comment_settings']);
unset($form['path']);
unset($form['revision_information']);
unset($form['author']);
}
}
但是 - 我找不到(即使在调试器中)要取消设置的变量以禁用输入格式选项以防止用户更改默认格式。 你还有其他方法吗?
I am using hook_form_alter to disable some publishing options whet authors adds or edits the nodes:
/**
* hook_form_alter ()
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
global $user;
if ($form['#id'] == 'node-form') {
unset($form['comment_settings']);
unset($form['path']);
unset($form['revision_information']);
unset($form['author']);
}
}
However - I can not find (even in debugger) what variable to unset to disable Input Format options to prevent users from changing default format.
Do you other way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我们确保我们的钩子在filter_form_alter之后被调用(或者从任何其他模块改变表单的钩子),HOOK_FORM_ALTER将起作用。
这是通过将 drupal 系统表中的模块权重设置为大于我们的竞争对手来完成的。它通常在 hook_install 中完成:
Drupal 使用权重字段来确定顺序或调用挂钩。
摘自:
http://drupal.org/node/110238
希望它会对某人有所帮助。
HOOK_FORM_ALTER will work if we make sure our hook is being called after filter_form_alter (or hook from any other module altering form).
This is being done by setting our module weight in drupal system table to be bigger than others we compete with. It is usually done in hook_install:
Drupal uses weight field to determine order or calling hooks.
Taken from:
http://drupal.org/node/110238
Hope it will help someone.
嗯,为什么你不直接设置过滤器格式,这样普通用户就不会拥有多个过滤器格式,然后简单地删除每个人的管理过滤器权限,这不是“残酷”,而是所谓的“安全”。
Hm, why dont you just set up your filter formats so that normal users dont have more than one, and simply remove the administer filters permission from everyone, that's not 'cruel' that's called 'secure'.
禁用“管理过滤器”权限是可行的,但感觉有点残酷。
Disable "administer filters" permission works but it feels kind of cruel.