form_alter in drupal module
form_alter is basically the way we can change the defaults or behaviour of any form.
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
core : It is the version of drupal
Include following lines of code in mymod.module
<?php
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
ABOUT THE AUTHOR
Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible
0 comments:
Post a Comment