Skip to content

Instantly share code, notes, and snippets.

@v1talii-dev
Last active August 30, 2016 07:00
Show Gist options
  • Save v1talii-dev/cc8640baad86cda8ead47476e5274525 to your computer and use it in GitHub Desktop.
Save v1talii-dev/cc8640baad86cda8ead47476e5274525 to your computer and use it in GitHub Desktop.
D7: hook_menu() variants
# test.module
<?php
/**
* Implements hook_menu().
*
* @see https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x
*/
function mymodule_menu() {
# In main menu.
$items['test-main-menu'] = array(
'title' => t('Test main menu'),
'menu_name' => 'main-menu',
'weight' => 100,
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_goto',
'page arguments' => array('search'),
'access callback' => TRUE,
'options' => array(
'attributes' => array(
'class' => 'custom-link' // Add custom class.
)
)
);
# Form callback.
$items['test-form'] = array(
'title' => t('Test form'),
'description' => t(''),
'page callback' => 'drupal_get_form',
'page arguments' => array('form_example_form'),
'access callback' => TRUE,
);
# Admin pages.
# Callback return html.
$items['admin/config/services/test'] = array(
'title' => t('Test admin'),
'description' => t('Test'),
'page callback' => 'test_admin_page',
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'file' => 'admin/test_admin_page.inc',
);
# Api pages.
# Callback return array().
$items['api/%'] = array(
'page callback' => 'test_api',
'access callback' => true,
'page arguments' => array(1),
'delivery callback' => 'drupal_json_output',
'file' => 'api/test_api.inc',
);
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment