|
这个是非常常见的一个需求,但在Drupal 7中要做这个修改却比Drupal 6 繁琐得多。这里教大家Drupal 7 如何在Comments Textare 文本框中移除Text Format 选项/指南: 最为简单的方式是安装 Better formats 模块,但为了区区一个小功能而安装一个模块,是否有这样的必要呢?下面我们来探讨一下代码的方式实现。
我们需要做的是修改comment 表单。有两种方法: 方法1,修改template.php 文件实现 方法2,新建一个模块实现 选哪种方式随你,如果你想不通过theme 改变,那选择第二种方法。 Ok,把下面代码添加到你的自定义模块,或者是template.php 中: 1
+ D! \! p& O' ^. P3 {; E. }2' z( o1 D! u8 g% O7 A
3( p1 u) O% a8 y% A% h9 u
| function ModulNameOrYourThemeName_form_comment_form_alter(&$form, &$form_state, &$form_id) {$ d$ Z+ n+ j. k/ U
$form['comment_body']['#after_build'][] = 'ModulNameOrYourThemeName_customize_comment_form'; j7 ^' n. t( Z5 c$ j/ ?7 D
} |
可选 A: 如果你想 隐藏formatting guidelines 跟 Filter Tips link,增加下面function到文件中: 10 x" ^6 |7 J: i) G) J0 w
2* S7 x5 P3 ^: b) W
3# S. U9 \. ? u# J; p3 e
4
) _- m4 h$ Z3 a0 ?4 a5
: I" }% U* {0 a$ n6- F# N# }6 ^6 a" h
7
+ C) X+ U0 n) A( _ | function ModulNameOrYourThemeName_customize_comment_form(&$form) {7 F7 z) A( j6 l/ F, L
// Hide guideliness
/ P; }! G& s9 Q" _0 o3 h $form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE; // Note ‘und’, you may need to set your comment form language code instead! c Z, W0 M' f% o5 }
// Hide Filter Tips
9 s! w% f% _3 @8 Z. i% R $form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
7 Z; c/ _& ?+ I1 X' [ return $form;
4 Q5 y9 D1 B P9 K/ ~} |
可选 B: 如果你想隐藏整个format 选项,增加下面function 到文件中: 1
4 Z5 D. I, J B# _7 p* `9 |# x2
4 E0 L* d/ _/ u! }& D0 E38 r" w* H" \4 }6 E0 J0 }
41 U' w9 ^/ h- D
| function ModulNameOrYourThemeName_customize_comment_form(&$form) {
0 ]( r- F4 n/ B( q ^1 n $form[LANGUAGE_NONE][0]['format']['#access'] = FALSE; // Note LANGUAGE_NONE, you may need to set your comment form language code instead
. Z; X8 {: k4 W5 J& S return $form; 6 Z* r5 p H6 `0 v! D
} |
保存文件,同时别忘记清空缓存(Configuration > Development > Performance > Clear All Caches)。 怎么样?是不是很简单?
猪跑啦独家原创专稿,欢迎您转载本文,转载请注明来源。 |