In #979090: Node path 'cas' overrides CAS module 'cas' path, a user manually added a path 'cas' to a node which broke the functionality of the CAS login feature.

To prevent such errors, it would be convenient of path.module added a hook_path_validate() where a potential path alias could be validated by modules. The API might be something like

/**
 * Allow modules to validate to a path being created or updated.
 *
 * @param $path
 *   An associative array containing the following keys:
 *   - source: The internal system path.
 *   - alias: The URL alias.
 *   - pid: Unique path alias identifier.
 *   - language: The language of the alias.
 * @param $errors
 *   An array of human readable error messages.
 *
 * @see path_save()
 */
function hook_path_validate($path, &$errors) {
  if ($path['alias'] == 'user') {
    $errors[] = t('The path alias %path is reserved for %module.', array('%path' => 'user', '%module' => 'user.module));
  }
}

Or maybe something more like the field validation functionality (which is more complicated). I can't say I've thought about it very much... responses appreciated.

Comments

Dave Reid’s picture

Status: Active » Closed (duplicate)

I agree. I'm merging this into #121362: Do not allow existing or reserved paths as aliases as likely it would be a path_validate + hook_path_validate() that helps implement it.