Posts

Showing posts from May, 2012

Drupal - List User's Author

Drupal by default donot provide user's author detail in views or any where in data base. Once I went through this kind of requirnment to list users with detail, who created those users. A simple way in D7 is to add text field in "user_register_form". That field will be hidden and will get current user's detail in it. We will do this using a module with hook_form_alter. Say you added a text field in user registration form with name "field_authortxt" Add the following code in .module file function custom_user_author_form_alter(&$form, &$form_state, $form_id) { if(( $form_id == "user_register_form") || ( $form_id == "user_profile_form")){ $lang = $form['field_authortxt']['#language']; global $user; $form['field_authortxt'][$lang][0]['value']['#default_value'] = $user->name; $form['#after_build'][] = '_tansnippet_after_build'; } } Now we need to hid