[Drupal Pathauto][Drupal 7] How to hide the "URL path settings" fieldset?

| | 1 min read

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.

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.

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.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.