0

I am trying to do something that seems simple, but I have yet to have to do it with my development because I have always dealt with forms and views.

On the page that I get redirected to when I click on a menu item, I want to have a page with a href on it.

So for example, I have created a menu item as follows:

$items['admin/vendor/auth-stripe'] = array(
        'title' => 'Authenticate Stripe Account',
        'description' => 'In order to receive payments, you must authenticate your Stripe Account.',
        //'page callback' => '_bh_vendor_auth_stripe',
        'access arguments' => array('vendor administration'),
        'type' => MENU_NORMAL_ITEM,
);  

When I click on this menu item, I am taken to a page. I want to add items to this page. Namely an href link.

Do I need to create a block that only shows up on this page? If so, how do I add a link on the page. I know how to create a block programmatically using hook_block_info, but I am not exactly clear on putting content in this block programmatically.

2

hook_menu serves, among other things, to map paths onto callback functions. Whatever function is marked as the page callback for that path will be responsible for returning a either a rendered string of HTML or a Drupal render array. So, for your very simple use-case, you could do the following (assuming your module's name is bh_vendor):

function bh_vendor_menu() {
 $items['admin/vendor/auth-stripe'] = array(
        'title' => 'Authenticate Stripe Account',
        'description' => 'In order to receive payments, you must authenticate your Stripe Account.',
        'page callback' => '_bh_vendor_auth_stripe',
        'access arguments' => array('vendor administration'),
        'type' => MENU_NORMAL_ITEM,
 );
 return $items;
}

function _bh_vendor_auth_stripe() {
 return l('My link', 'my/path');
}

You could, in fact, define a block using hook_block_info() and hook_block_view(), then embed that block on your page by calling module_invoke('bh_vendor', 'block_view', 'yourblockdeltahere') but that really only makes sense if the stuff you're embedding is re-used elsewhere. If it's only meant for this one page then you should stick the code to generate that markup in your page callback directly.

Another option, if this isn't for a module that's to be widely distributed and is only configuration for a specific site: use the Panels module. You can create a panels page at a specific url (admin/vendor/auth-stripe) and embed whatever blocks/content you wish. If you want it in code it is exportable and/or can integrate with Features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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