有没有办法干净地重写 /includes/form.inc 中的函数“form_execute_handlers(...)”?
问题是 /modules/user/user.pages.inc 中有一些像“user_profile_form_validate(...)”这样的处理函数无法被“form.inc”的核心版本找到,因为以下语句对于这种特殊情况,“form_execute_handlers(...)”中缺少:
module_load_include('inc', 'user', 'user.pages');
我想以某种方式添加它,因此覆盖 form.inc ;)
好的,我找到了一种包含该库的方法(在我的自定义模块中):
function wr_pages_init() {
if (($_GET['q'] == 'system/ajax' || strstr($_GET['q'], 'file/ajax/')) && $_POST['form_id'] == "user_profile_form") {
module_load_include('inc', 'user', 'user.pages');
}
}
永远不要改变核心功能!更新 drupal 将覆盖您的更改,根本不是一个好的做法。请记住,所有其他模块也使用核心,因此如果您搞乱核心,事情就会变得非常错误。
您可以像这样自定义用户表单(链接到其他答案):
还有用于更改表单处理的挂钩。因此,您可以像这样更改用户表单验证:
hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_profile_form') {
$form['#validate'][] = 'your_validation_function';
}
}
或者如果您只想使用自己的验证更改:
$form['#validate'] = array('your_validation_function');
包含用户库时无需检查查询。只需包含它即可:
function wr_pages_init() {
module_load_include('inc', 'user', 'user.pages');
// And other includes (if needed) same way.. like:
// Add jquery ui libraries..
drupal_add_library('system', 'ui');
drupal_add_library('system', 'ui.sortable');
drupal_add_library('system', 'ui.datepicker');
// Add ajax..
drupal_add_library('system', 'drupal.ajax');
// Some own JS
drupal_add_js(drupal_get_path('module', 'wr_pages') . '/js/mysuper.js', 'file');
}