Is there a way to override user_admin_account? - drupal

I need to override the user_admin_account function (which list users in backoffice).
Is there a way to do that without modify the core? I don't see any hook to do that.

That function is a form so you can implement hook_form_alter() in a custom module (or even a theme as it's an alter hook).
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_admin_account') {
$form['something']['#default_value'] = 'something else';
}
}

Related

How to make user email non-required upon registration in drupal 7?

How to make user email non-required (optional) upon registration in drupal 7?
I was able to make a custom module. It's really similar to sharedemail.
<?php
function noemail_form_user_register_form_alter(&$form, &$form_state, $form_id) {
noemail_form_user_account_form_alter($form, $form_state, $form_id);
}
function noemail_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
noemail_form_user_account_form_alter($form, $form_state, $form_id);
}
function noemail_form_user_account_form_alter(&$form, &$form_state, $form_id) {
if (is_array($form['#validate'])) {
$key = array_search( 'user_account_form_validate', $form['#validate'], TRUE );
if ( $key !== FALSE ) {
$form['#validate'][$key] = 'noemail_account_form_validate';
}
}
$form['account']['mail']['#required'] = FALSE;
}
function noemail_account_form_validate($form, &$form_state) {
$form['account']['mail']['#needs_validation'] = false;
}
and the install file in case it's key
<?php
function sharedemail_install() {
db_query("UPDATE {system} SET weight = -99 WHERE name = 'noemail'");
}
Hope this helps, wow this is a really old thread. Oh and note this is for d7
You can't really change another validation hook.
What you could try to do is build your own validation and on that form's validation (['#validate']) array only instantiate your own validation hook.
There is a optional mail module that makes the email field optional in user registration. Visit https://www.drupal.org/project/optional_mail ,
I hope it helps.
You could override the #required setting on the field using the Form API inside of a custom module with a hook_form_alter implementation.

Drupal: run custom code when a form is submitted

how can I run specific code when a form is submitted in Drupal ?
I'm using hook_form_alter to edit the form, but I actually need to collect the data inserted by user and run code when the user click on "Save / Register" etc
thanks
You can add callbacks to the submit array. It goes something like this:
function myform_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'some_form') {
$form['#submit'][] = 'mycallback';
}
}
function mycallback(&$form, &$form_state) {
// do stuff
}
Try adding the following function:
function myform_form_submit($form_id, $form_values){
print_r($form_values);
// custom code
}
worked for me. Hope it helps :)

drupal6 error ajax inline

How can i set a custom inline error messages to form in a node (include cck and all the stuff) ?
I saw several modules, but none of them give a 100% solution, because there is no CCK-support, upload-support, error messages etc.
I'm guessing you are looking to do custom validation on a CCK field?
In that case you can add your function by creating a module and implementing hook_form_alter() and creating your own validation function.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'story_node_form': // Or whatever content type you're checking
// Simply add an additional link validate handler.
$form['#validate'][] = 'mymodule_field_validate';
break;
}
}
function mymodule_field_validate($form, &$form_state) {
if (!somevalidatorfunctionorother($form_state['values']['my_custom_field']) {
form_set_error('my_custom_field', t('Text of your error message.'));
}
}
I adapted the code above from this post: http://fleetthought.com/adding-additional-cck-validation-function-field-using-hookformalter

Double output within Drupal function

I'm going crazy
function module_form_alter(&$form, $form_state, $form_id) {
// Nothing here
$var = 'bla-bla';
print_r($var);
// Nothing here
}
I see on the screen bla-blabla-bla
WHY?
You probably have two forms on the page. Try printing (better yet, install devel and use dpm) $form_id instead of $var and see which forms are involved.
hook_form_alter works on every form. You probably have the search form in this page, so it prints the text twice (one for every form).
In order to add changes to only one form, use the $form_id argument like this:
function module_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'YOURFORMID') {
$var = 'bla-bla';
print_r($var);
}
}
change YOURFORMID to your form_id.
You can find the form_id by looking on the HTML of the form output and search the value of the input that his name is 'form_id'.

drupal form alter

I'm developing a module which alter display of add/edit node forms. I'm a beginner in module development.
I have written following code, it is not working properly. Please tell me what's wrong with this?
function hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_form') {
drupal_set_message(t('some message.'));
}
}
This is for drupal 6.
In addition, the node add/edit forms have content-type specific IDs. so story nodes would be:
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'story_node_form') {
drupal_set_message(t('Editing a story node!'));
}
}
If you're looking to catch every node edit form, regardless of type, try this:
function mymodule_form_alter(&$form, $form_state, $form_id) {
if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
drupal_set_message(t('Editing a node!'));
}
}
you should not call your function "hook_form_alter" but rather "yourmodule_form_alter". yourmodule should be the name of your module file, so if your module is called "hello" the function name should be "hello_form_alter".
You need to understand the hook system that Drupal uses if you want to do module development. When a hook is implemented somewhere in Drupal, it's called hook_something. The way this works is that every time a module wants to implement the hook, you need to replace the 'hook' with the 'modelname'. Drupal will know it's an instance of that hook and call it as such. Drupal also uses the same system in the theming layer, with a twist. As it will look at the different theming functions and prioritize them based on a ranking system, that enabled themes to override the way modules output data.
function hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_form') {
drupal_set_message(t('some message.'));
}
}
First you must "hook" keyword to your module keyword.. lets suppose your module name is "contact_us" then
function contact_us_form_alter(&$form, $form_state, $form_id) {
Now this function has three variable
$form
$form_id
$form_state
Most important variable during form alter is $form_id which basically note down which form is load in a page.
function contact_us_form_alter(&$form, $form_state, $form_id) {
print_r($form_id);exit; // Used to find the form id
}
after you find the form_id
function contact_us_form_alter(&$form, $form_state, $form_id) {
if($form_id=='contact_us_form')
// Do your stuff
}
Note:check you have properly write custom module and enable it.. also clear cache

Resources