From a4200e73acf4e0a5852cbbc48706b9077cbf4a48 Mon Sep 17 00:00:00 2001 From: Tim Erickson Date: Sun, 23 Jun 2024 04:33:02 -0500 Subject: [PATCH 1/4] Making some changes to documentation and code. --- menu_example/menu_example.module | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/menu_example/menu_example.module b/menu_example/menu_example.module index bdeb194..92c6533 100644 --- a/menu_example/menu_example.module +++ b/menu_example/menu_example.module @@ -28,7 +28,7 @@ function menu_example_menu() { // Menu items are defined by placing them in an $items array. The array key // (in this case 'menu_example') is the path that defines the menu router - // entry, so the page will be accessible from the URL + // entry, so the page will be accessible from the following URL // example.com/examples/menu_example. $items['examples/menu_example'] = array( // We are using the default menu type, so this can be omitted. @@ -39,9 +39,14 @@ function menu_example_menu() { // in the 'menu_example/title_callbacks' example below. 'title' => 'Menu Example', + // Unless a 'menu_name' is assigned. Menu items will be assigned to an + // invisible internal menu. This menu item will be assigned to the primary + // navigation menu (main-menu). + 'menu_name' => 'main-menu', + // Description (hover flyover for menu link). Does NOT use t(), which is // called automatically. - 'description' => 'Simplest possible menu type, and the parent menu entry for others', + 'description' => 'Simplest possible menu link that is not visible to anyone yet.', // Function to be called when this path is accessed. 'page callback' => '_menu_example_basic_instructions', @@ -67,30 +72,23 @@ function menu_example_menu() { 'expanded' => TRUE, ); - // Show a menu link in a menu other than the default "Navigation" menu. - // The menu must already exist. - $items['examples/menu_example_alternate_menu'] = array( - 'title' => 'Menu Example: Menu in alternate menu', - - // Machine name of the menu in which the link should appear. - 'menu_name' => 'user-menu', - + // Unless otherwise specified, menu items are assigned to the invisible + // internal menu. This link is accessible, but not visible due to lack of + // any 'menu_name' or visible parent menu. Below, this and all other $items + // will be added to the menu_example_menu created by this module. + $items['examples/menu_example_internal'] = array( + 'title' => 'Menu Example Internal', 'page callback' => '_menu_example_menu_page', - 'page arguments' => array(t('This will be in the Primary Links menu instead of the default Navigation menu')), + 'page arguments' => array(t('A simple menu item assigned to the invisible intenal menu.')), 'access callback' => TRUE, + 'expanded' => TRUE, ); // A menu entry with simple permissions using user_access(). // // First, provide a courtesy menu item that mentions the existence of the // permissioned item. - $items['examples/menu_example/permissioned'] = array( - 'title' => 'Permissioned Example', - 'page callback' => '_menu_example_menu_page', - 'page arguments' => array(t('A menu item that requires the "access protected menu example" permission is at examples/menu_example/permissioned/controlled', array('!link' => url('examples/menu_example/permissioned/controlled')))), - 'access callback' => TRUE, - 'expanded' => TRUE, - ); + // Now provide the actual permissioned menu item. $items['examples/menu_example/permissioned/controlled'] = array( @@ -311,6 +309,10 @@ function menu_example_menu() { 'access callback' => TRUE, 'weight' => 80, ); + + // This statement adds each of the $items to the new menu-example-menu + // that was created by this module. This menu is intially not visible, but + // may be placed in any layout and will then display all of these links. foreach ($items as $path => $item) { if (!isset($item['menu_name'])) { $items[$path]['menu_name'] = 'menu-example-menu'; From 913d975bcff1f3460bd53185797c1629c9755875 Mon Sep 17 00:00:00 2001 From: Tim Erickson Date: Sun, 23 Jun 2024 04:40:16 -0500 Subject: [PATCH 2/4] Restoring accidental change to description for link. --- menu_example/menu_example.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menu_example/menu_example.module b/menu_example/menu_example.module index 92c6533..03283a8 100644 --- a/menu_example/menu_example.module +++ b/menu_example/menu_example.module @@ -46,7 +46,7 @@ function menu_example_menu() { // Description (hover flyover for menu link). Does NOT use t(), which is // called automatically. - 'description' => 'Simplest possible menu link that is not visible to anyone yet.', + 'description' => 'Simplest possible menu type, and the parent menu entry for others.', // Function to be called when this path is accessed. 'page callback' => '_menu_example_basic_instructions', From 7a84b365e80b68f4ed746dd22f062a07647a40ed Mon Sep 17 00:00:00 2001 From: Tim Erickson Date: Sun, 23 Jun 2024 04:43:24 -0500 Subject: [PATCH 3/4] Restoring accidentally deleted item --- menu_example/menu_example.module | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/menu_example/menu_example.module b/menu_example/menu_example.module index 03283a8..11fda9e 100644 --- a/menu_example/menu_example.module +++ b/menu_example/menu_example.module @@ -88,7 +88,13 @@ function menu_example_menu() { // // First, provide a courtesy menu item that mentions the existence of the // permissioned item. - + $items['examples/menu_example/permissioned'] = array( + 'title' => 'Permissioned Example', + 'page callback' => '_menu_example_menu_page', + 'page arguments' => array(t('A menu item that requires the "access protected menu example" permission is at examples/menu_example/permissioned/controlled', array('!link' => url('examples/menu_example/permissioned/controlled')))), + 'access callback' => TRUE, + 'expanded' => TRUE, + ); // Now provide the actual permissioned menu item. $items['examples/menu_example/permissioned/controlled'] = array( From c73e89d1fc668fec0ce6d99251ae270c502573fa Mon Sep 17 00:00:00 2001 From: "Tim Erickson (@stpaultim)" Date: Sun, 23 Jun 2024 19:34:34 -0500 Subject: [PATCH 4/4] More tweaks to text --- menu_example/menu_example.module | 70 +++++++++++++++++--------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/menu_example/menu_example.module b/menu_example/menu_example.module index 11fda9e..f5adb57 100644 --- a/menu_example/menu_example.module +++ b/menu_example/menu_example.module @@ -20,6 +20,36 @@ * @see page_example_menu() */ +/** + * Implements hook_permission(). + * + * Provides a demonstration access string. + * Using this for later examples. + */ +function menu_example_permission() { + return array( + 'access protected menu example' => array( + 'title' => t('Access the protected menu example'), + ), + ); + +} + +/** + * Determine whether the current user has the role specified. + * Here for use in later examples. + * + * @param string $role_name + * The role required for access + * + * @return bool + * True if the acting user has the role specified. + */ +function menu_example_custom_access($role_name) { + $access_granted = in_array($role_name, $GLOBALS['user']->roles); + return $access_granted; +} + /** * Implements hook_menu(). * @@ -74,8 +104,9 @@ function menu_example_menu() { // Unless otherwise specified, menu items are assigned to the invisible // internal menu. This link is accessible, but not visible due to lack of - // any 'menu_name' or visible parent menu. Below, this and all other $items - // will be added to the menu_example_menu created by this module. + // any 'menu_name' or visible parent menu. Later in this code, this and + // all other $items will be added to the menu_example_menu created by + // this module. $items['examples/menu_example_internal'] = array( 'title' => 'Menu Example Internal', 'page callback' => '_menu_example_menu_page', @@ -87,7 +118,8 @@ function menu_example_menu() { // A menu entry with simple permissions using user_access(). // // First, provide a courtesy menu item that mentions the existence of the - // permissioned item. + // permissioned item. This link is accessible to everyone, but the following + // "controlled" link is limited to admins. $items['examples/menu_example/permissioned'] = array( 'title' => 'Permissioned Example', 'page callback' => '_menu_example_menu_page', @@ -201,6 +233,7 @@ function menu_example_menu() { // Now add the rest of the tab entries. foreach (array(t('second') => 2, t('third') => 3, t('fourth') => 4) as $tabname => $weight) { $items["examples/menu_example/tabs/$tabname"] = array( + // Without this 'type' these links would show up as normal menu links. 'type' => MENU_LOCAL_TASK, 'title' => $tabname, 'page callback' => '_menu_example_menu_page', @@ -219,10 +252,10 @@ function menu_example_menu() { $items['examples/menu_example/tabs/default/first'] = array( 'type' => MENU_DEFAULT_LOCAL_TASK, 'title' => 'Default secondary tab', - // The additional page callback and related items are handled by the + // The additionalred page callback and related items are handled by the // parent menu item. ); - foreach (array(t('second'), t('third')) as $tabname) { + foreach (array(t('red'), t('green')) as $tabname) { $items["examples/menu_example/tabs/default/$tabname"] = array( 'type' => MENU_LOCAL_TASK, 'title' => $tabname, @@ -364,33 +397,6 @@ function _menu_example_menu_page($content = NULL, $arg1 = NULL, $arg2 = NULL) { return $output; } -/** - * Implements hook_permission(). - * - * Provides a demonstration access string. - */ -function menu_example_permission() { - return array( - 'access protected menu example' => array( - 'title' => t('Access the protected menu example'), - ), - ); - -} - -/** - * Determine whether the current user has the role specified. - * - * @param string $role_name - * The role required for access - * - * @return bool - * True if the acting user has the role specified. - */ -function menu_example_custom_access($role_name) { - $access_granted = in_array($role_name, $GLOBALS['user']->roles); - return $access_granted; -} /** * Utility function to provide mappings from integers to some strings.