form_alter is basically the way we can change the defaults or behaviour of any form.
name : it is the name of the module.
description : it is the description for the module
In the above code, default value will be set to 0 (i,e. uncheck) for the node id node_form
hook_form_alter(&$form, &$form_state, $form_id)
It performs alteration before rendering. It is also used to add form elements to the Node form. The node object can be accessed at $form['#node'], when altering the node form.
$form: It is the nested array of form elements.
$form_state: A keyed array containing the current state of the form.
$form_id: String representing the name of the form itself.
Lets continue with an example of adding a content type. When you navigate to Structure >> Content type >> Add content type and scroll down you can find Display settings
By default, the value has been checked. Lets uncheck it by using form_alter in a module.
Create a folder in sites >> all >> module named as mymod. Inside that folder create two files mymod.info and mymod.module.
Include following lines of code in mymod.info
By default, the value has been checked. Lets uncheck it by using form_alter in a module.
Create a folder in sites >> all >> module named as mymod. Inside that folder create two files mymod.info and mymod.module.
Include following lines of code in mymod.info
name = mymod
description = This description for mymod
core = 7.x
description : it is the description for the module
core : It is the version of drupal
Include following lines of code in mymod.module
function mymod_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'node_form'){
$form['display']['node_submitted']['#default_value'] = 0;
}
}
We can also change the description which is appearing below the check box by including the following lines
$form['display']['node_submitted']['#description'] = t("This is the description");
ZenRays provide the following to make you expert
zenrays providing drupal training in Bangalore
- Fully practical and project-based sessions from first class.
- Training by Experienced Consultants, not regular Trainers
- Friendly and enthusiastic faculty to clear your doubts 24X7
- Free Live project after the training to get you industry experience
If you want more details please visit us:
Zenrays.com Reach us at [email protected]
This post first appeared on Best Software Training Institute In Bangalore, please read the originial post: here