A number of Drupal users wanted to know how to hide the URL path settings fieldset in a Drupal 7 website. If you are a Drupal user facing the same question in your Drupal site with your Drupal Pathauto module even after using hook_form_alter then read on to find out the solution.
许多Drupal用户都知道在Drupal 7站点里隐藏URL路径设置,如果你也是一个在Drupal站点里应用了Drupal Pathauto模块,并遇到同样问题的Drupal用户,尽管在使用hook_form_alter之后仍然不起效果之后,可以看看下面的解决方案。
A hook_form_alter cannot be used to hide the URL path settings fieldset as the fieldset gets added in path_form_alter which runs after node_form_alter as both the modules have similar weight. To get around this you need to use a #after_build item in your form alter as shown below.
hook_form_alter勾子并不能被用于隐藏URL 路径设置,因为这个字段是path_form_alter里加入的,而这个path_form_alter是在node_form_alter之后被执行的,因为这两个模块(node,page)具有相同的权重。要避免这个问题,你需要在你的form alter里使用一个“#after_build” 项,参考下面的代码:
function custom_form_alter(&$form, &$form_state){
$form['#after_build'][] = 'custom_after_build';
....
}
function custom_after_build($form, &$form_state) {
$form['path']['#access'] = FALSE;
$form['menu']['#access'] = FALSE;
return ($form);
}
The above code will remove the form elements from the form after the build of the form is initialized.
上面的代码就可以在表单初始化完成并建立表单后移除表单元素,
Hope that helps.
希望有所帮助。
原文地址: