0

I have a custom module that spits out a form using the drupal form API. What I'd like to do is output a block (a custom menu) in a particular region of the page (using block regions would be the best way I'm guessing.) As of now, the block renders in the top left everytime. How can I output the menu block in a particular region of the page?

function client_menu(){

 $items=array();

 $items['campaign']=array(

   'title'=>'Campaign Manager',
   'description'=>'Area for clients to manage their campaigns',
   'page callback'=>'drupal_get_form',
   'page arguments'=>array('client_campaign'),
   'access arguments'=>array('access client administration'),
   'type'=>MENU_NORMAL_ITEM   
 );

 return $items;

}

function client_campaign(){

$block = module_invoke('menu', 'block_view', 'menu-client-admin');
print render($block);

//a bunch of form API stuff...

}

1 Answer 1

1

Why aren't you creating a standard block which returns your form? Currently you have a page callback (http://yoursite.com/campaign), and you are injecting this into a block ...

Here is some sample code that could help you further:

function client_block_info()
{
    $blocks = array();

    $blocks['client_campaign'] = array(
        'info' => t('Area for clients to manage their campaigns'),
        'title' => t('Campaign Manager'),
        'region' => 'content', // Your desired region, can be edited in administration screen
        'status' => 1,
    );

    return $blocks;
}

function client_block_view($delta = '')
{
    $block = array();

    switch ($delta) {
        case 'client_campaign' :
            $block['content'] = client_block_content();
            break;
    }

    return $block;
}

function client_block_content()
{
    return drupal_get_form('client_campaign');
}

function client_campaign($form, &$form_state)
{
    // Build your form

    return $form
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.