覆盖Drupal 7中的核心功能

时间:2014-02-22 23:28:48

标签: drupal-7 override core

有没有办法干净地覆盖在/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');
  }
}

1 个答案:

答案 0 :(得分:1)

永远不要改变核心功能!更新drupal将覆盖您的更改,并不是一个好习惯。请记住,所有其他模块也使用核心,所以如果你搞乱核心,事情就会变得非常糟糕。

您可以像这样自定义用户表单(链接到其他答案):

drupal 7 cusomized user profile template can not save changes

还有用于改变表单处理的钩子。因此,您可以更改用户表单验证:

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');

}
相关问题