Last active
August 30, 2016 07:00
-
-
Save v1talii-dev/cc8640baad86cda8ead47476e5274525 to your computer and use it in GitHub Desktop.
D7: hook_menu() variants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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