phpdrupal-7overriding

Override core functionality in Drupal 7


is there a way to cleanly override the function "form_execute_handlers(...)" which is found in /includes/form.inc ?

The problem is that there are some handler-functions like "user_profile_form_validate(...)" in /modules/user/user.pages.inc which cannot be found by the core version of "form.inc", since the following statement is missing in "form_execute_handlers(...)" for this special case:

module_load_include('inc', 'user', 'user.pages');

I would like to add that somehow, and therefore override form.inc ;)

Ok, I found a way to include the library (inside my custom module):

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

Solution

  • Never change core functionality! Updating drupal will override your changes and is not good practice at all. Keep in mind that all other modules uses core too so things goes really wrong if you mess with core.

    You can do custom user form like this (link to other answer):

    drupal 7 cusomized user profile template can not save changes

    There is also hooks for altering form handling. So you can change user form validation like this:

    hook_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'user_profile_form') {
        $form['#validate'][] = 'your_validation_function';
      }
    }
    

    Or if you want only to use your own validation change:

    $form['#validate'] = array('your_validation_function');
    

    You don't have to check queries when including user library. Just include it like:

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