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.
希望有所幫助。
原文地址: