Thursday, February 16, 2012

Why hook_form not working

Why hook_form not working

Hi Googler,
i was working on drupal and come to know this problem, 


I have a module which I have defined a hook_form hook,
but it was not working, after some investigation I have found that hook_form is only called when a node type is defined by a module.
so, what is mean by “a node type defined by a module”?
In drupal , we can define a module type in 2 place, one is in module’s installation file.
for example:




$test_type = array(
    ‘type’ => ‘test’,
    ‘name’ => st(‘Test’),
    ‘module’ => ‘node’,
    ‘custom’ => TRUE,
    ‘modified’ => TRUE,
    ‘locked’ => FALSE,
  );
  $test_type = (object) _node_type_set_defaults($test_type);
  node_type_save($test_type);





above code, create a node type through “node_type_save” , function.
the other place is use hook_node_info function in a module file.
for example:


function test_node_info() {
  return array(
    ‘teiqcase’ => array(
      ‘name’ => t(‘test’),
      ‘module’ => ‘test’,
      ‘description’ => t(“Test”),
      ‘has_title’ => TRUE,
      ‘title_label’ => t(‘Test’),
      ‘has_body’ => FALSE,
      ‘body_label’ => t(‘Body’),
    ),
  );
}





above also create a node type ‘test’ , but this one did not use ‘node_type_save’ function, hence, it called “a node type defined by a module”.
so to make a node type work with “hook_form”, we should not use ‘node_type_save’ to define a node type, but use “hook_node_info” to define a node type
above only works for Drupal 6, drupal 7′s hook_form is totally different.

Know More About :
PHP Freelancing India


Reactions:

0 comments:

Post a Comment

Any Questions or Suggestions ?

About

Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner

PHP Freelancer India - Google+