I have a module, and I would like its add form to be put into a block. So my question is, how would you take a modules page (admin/build/mymodule/add) and give it a block? So this module will now have its own block in the blocks admin page. Do you do this by its url, by module, or by form id?
2 Answers
You can do this with the $form_id and the function drupal_get_form();
You need to create a module and use hook_block()
:
function mysecondmodule_block($op = 'list', $delta = 0, $edit = array()) {
switch($op) {
case 'list':
return array(array('info' => 'mymodule add block'));
break;
case 'view':
if($delta == 0) {
return array(
'subject' => 'Mymodule Add',
'content' => drupal_get_form('form-id');
);
}
break;
}
}
function mysecondmodule_block($op='list',$delta=0,$edit=array()){
switch($op) {
case 'list':
return array(array('info'=>'mymodule add block'));
break;
case'view';
if($delta==0){
return array(
'subject'=>'Mymodule Add',
'content'=> drupal_get_form('form-id');
);
}